public class MediaFoundationEncoder : IWriteable, IDisposable
A generic encoder for all installed Mediafoundation-Encoders.
MediaFoundationEncoder(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)
Creates an new instance of the MediaFoundationEncoder class.
public void MediaFoundationEncoder(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)
Parameters
inputMediaType
MFMediaTypeMediatype of the source to encode.
stream
StreamStream which will be used to store the encoded data.
targetMediaType
MFMediaTypeThe format of the encoded data.
containerType
GuidSee container type. For a list of all available container types, see TranscodeContainerTypes.
CreateAACEncoder(WaveFormat sourceFormat, Stream targetStream, Int32 bitRate)
Returns a new instance of the MediaFoundationEncoder class, configured as aac encoder.
public static MediaFoundationEncoder CreateAACEncoder(WaveFormat sourceFormat, Stream targetStream, Int32 bitRate)
Parameters
sourceFormat
WaveFormatThe input format, of the data to encode.
bitRate
Int32The bitrate to use. The final bitrate can differ from the specified value.
targetStream
StreamThe stream to write to.
Returns
A new instance of the MediaFoundationEncoder class, configured as aac encoder.
Remarks
For more information about supported input and output formats, see .
CreateAACEncoder(WaveFormat sourceFormat, String targetFilename, Int32 bitRate)
Returns a new instance of the MediaFoundationEncoder class, configured as aac encoder.
public static MediaFoundationEncoder CreateAACEncoder(WaveFormat sourceFormat, String targetFilename, Int32 bitRate)
Parameters
sourceFormat
WaveFormatThe input format, of the data to encode.
bitRate
Int32The bitrate to use. The final bitrate can differ from the specified value.
targetFilename
StringThe file to write to.
Returns
A new instance of the MediaFoundationEncoder class, configured as aac encoder.
Remarks
For more information about supported input and output formats, see .
CreateMP3Encoder(WaveFormat sourceFormat, Stream targetStream, Int32 bitRate)
Returns a new instance of the MediaFoundationEncoder class, configured as mp3 encoder.
public static MediaFoundationEncoder CreateMP3Encoder(WaveFormat sourceFormat, Stream targetStream, Int32 bitRate)
Parameters
sourceFormat
WaveFormatThe input format, of the data to encode.
bitRate
Int32The bitrate to use. The final bitrate can differ from the specified value.
targetStream
StreamThe stream to write to.
Returns
A new instance of the MediaFoundationEncoder class, configured as mp3 encoder.
Remarks
For more information about supported input and output formats, see .
CreateMP3Encoder(WaveFormat sourceFormat, String targetFilename, Int32 bitRate)
Returns a new instance of the MediaFoundationEncoder class, configured as mp3 encoder.
public static MediaFoundationEncoder CreateMP3Encoder(WaveFormat sourceFormat, String targetFilename, Int32 bitRate)
Parameters
sourceFormat
WaveFormatThe input format, of the data to encode.
bitRate
Int32The bitrate to use. The final bitrate can differ from the specified value.
targetFilename
StringThe file to write to.
Returns
A new instance of the MediaFoundationEncoder class, configured as mp3 encoder.
Remarks
For more information about supported input and output formats, see .
CreateWMAEncoder(WaveFormat sourceFormat, Stream targetStream, Int32 bitRate)
Returns a new instance of the MediaFoundationEncoder class, configured as wma encoder.
public static MediaFoundationEncoder CreateWMAEncoder(WaveFormat sourceFormat, Stream targetStream, Int32 bitRate)
Parameters
sourceFormat
WaveFormatThe input format, of the data to encode.
bitRate
Int32The bitrate to use. The final bitrate can differ from the specified value.
targetStream
StreamThe stream to write to.
Returns
A new instance of the MediaFoundationEncoder class, configured as wma encoder.
Remarks
For more information about supported input and output formats, see .
CreateWMAEncoder(WaveFormat sourceFormat, String targetFilename, Int32 bitRate)
Returns a new instance of the MediaFoundationEncoder class, configured as wma encoder.
public static MediaFoundationEncoder CreateWMAEncoder(WaveFormat sourceFormat, String targetFilename, Int32 bitRate)
Parameters
sourceFormat
WaveFormatThe input format, of the data to encode.
bitRate
Int32The bitrate to use. The final bitrate can differ from the specified value.
targetFilename
StringThe file to write to.
Returns
A new instance of the MediaFoundationEncoder class, configured as wma encoder.
Remarks
For more information about supported input and output formats, see .
Dispose()
Releases all resources used by the encoder and finalizes encoding.
public void Dispose()
Dispose(Boolean disposing)
Disposes the MediaFoundationEncoder.
protected virtual void Dispose(Boolean disposing)
Parameters
disposing
BooleanTrue to release both managed and unmanaged resources; false to release only unmanaged resources.
EncodeWholeSource(MediaFoundationEncoder encoder, IWaveSource source)
Encodes the whole source with the specified encoder. The encoding process stops as soon as the Read method of the specified source returns 0.
public static void EncodeWholeSource(MediaFoundationEncoder encoder, IWaveSource source)
Parameters
encoder
MediaFoundationEncoderThe encoder which should be used to encode the audio data.
source
IWaveSourceThe IWaveSource which provides the raw audio data to encode.
Finalize()
Finalizes an instance of the MediaFoundationEncoder class.
protected void Finalize()
FindBestMediaType(Guid audioSubType, Int32 sampleRate, Int32 channels, Int32 bitRate)
Tries to find the MediaType which fits best the requested format specified by the parameters: sampleRate, channels, bitRate and audioSubType.
protected static MFMediaType FindBestMediaType(Guid audioSubType, Int32 sampleRate, Int32 channels, Int32 bitRate)
Parameters
audioSubType
GuidThe audio subtype. For more information, see the AudioSubTypes class.
sampleRate
Int32The requested sample rate.
channels
Int32The requested number of channels.
bitRate
Int32The requested bit rate.
Returns
A MediaType which fits best the requested format. If no mediatype could be found the FindBestMediaType method returns null.
GetEncoderMediaTypes(Guid audioSubType)
Returns all MFMediaTypes available for encoding the specified audioSubType.
public static MFMediaType[] GetEncoderMediaTypes(Guid audioSubType)
Parameters
audioSubType
GuidThe audio subtype to search available MFMediaTypes for.
Returns
Available MFMediaTypes for the specified audioSubType. If the GetEncoderMediaTypes returns an empty array, no encoder for the specified audioSubType was found.
SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)
Sets and initializes the targetstream for the encoding process.
protected void SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)
Parameters
stream
StreamStream which should be used as the targetstream.
inputMediaType
MFMediaTypeMediatype of the raw input data to encode.
targetMediaType
MFMediaTypeMediatype of the encoded data.
containerType
GuidContainer type which should be used.
Write(Byte[] buffer, Int32 offset, Int32 count)
Encodes raw audio data.
public void Write(Byte[] buffer, Int32 offset, Int32 count)
Parameters
buffer
Byte[]A byte-array which contains raw data to encode.
offset
Int32The zero-based byte offset in buffer at which to begin encoding bytes to the underlying stream.
count
Int32The number of bytes to encode.
EncodedDuration
Gets the total duration of all encoded data.
public TimeSpan EncodedDuration { get; }
OutputMediaType
Gets the media type of the encoded data.
public MFMediaType OutputMediaType { get; }
SinkWriter
Gets the MFSinkWriter which is used to write to the TargetStream.
protected MFSinkWriter SinkWriter { get; set; }
TargetBaseStream
Gets the underlying stream which operates as encoding target.
public Stream TargetBaseStream { get; }
TargetStream
Gets the destination stream which is used to store the encoded audio data.
protected MFByteStream TargetStream { get; set; }