Пример #1
0
        /// <summary>
        ///     Returns a new instance of the <see cref="MediaFoundationEncoder"/> class, configured as wma encoder.
        /// </summary>
        /// <param name="sourceFormat">The input format, of the data to encode.</param>
        /// <param name="bitRate">The bitrate to use. The final bitrate can differ from the specified value.</param>
        /// <param name="targetStream">The stream to write to.</param>
        /// <remarks>For more information about supported input and output formats, see <see href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff819498(v=vs.85).aspx"/>.</remarks>
        /// <returns>A new instance of the <see cref="MediaFoundationEncoder"/> class, configured as wma encoder.</returns>
        // ReSharper disable once InconsistentNaming
        public static MediaFoundationEncoder CreateWMAEncoder(WaveFormat sourceFormat, Stream targetStream,
                                                              int bitRate = 192000)
        {
            if (sourceFormat == null)
            {
                throw new ArgumentNullException("sourceFormat");
            }
            if (targetStream == null)
            {
                throw new ArgumentNullException("targetStream");
            }
            if (targetStream.CanWrite != true)
            {
                throw new ArgumentException("Stream not writeable.", "targetStream");
            }

            MediaType targetMediaType = FindBestMediaType(AudioSubTypes.WindowsMediaAudio,
                                                          sourceFormat.SampleRate, sourceFormat.Channels, bitRate);
            MediaType sourceMediaType = MediaFoundationCore.MediaTypeFromWaveFormat(sourceFormat);

            if (targetMediaType == null)
            {
                throw new PlatformNotSupportedException("No WMA-Encoder was found.");
            }

            return(new MediaFoundationEncoder(targetStream, sourceMediaType, targetMediaType,
                                              TranscodeContainerTypes.MFTranscodeContainerType_ASF));
        }
Пример #2
0
 static MediaFoundationDecoder()
 {
     MediaFoundationCore.Startup(); //make sure that the MediaFoundation is started up.
 }
Пример #3
0
 static MediaFoundationEncoder()
 {
     MediaFoundationCore.Startup();
 }
Пример #4
0
 private SourceReader Initialize(ByteStream byteStream)
 {
     return(Initialize(MediaFoundationCore.CreateSourceReaderFromByteStream(byteStream, null)));
 }