Methods (15) Properties (5)
Namespace: CSCore.MediaFoundation

Syntax

public class MediaFoundationEncoder : IWriteable, IDisposable

Implements

Summary

A generic encoder for all installed Mediafoundation-Encoders.

Uses

Methods

public void MediaFoundationEncoder(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)

Parameters

inputMediaType

MFMediaType

Mediatype of the source to encode.

stream

Stream

Stream which will be used to store the encoded data.

targetMediaType

MFMediaType

The format of the encoded data.

containerType

Guid

See 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

WaveFormat

The input format, of the data to encode.

bitRate

Int32

The bitrate to use. The final bitrate can differ from the specified value.

targetStream

Stream

The 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

WaveFormat

The input format, of the data to encode.

bitRate

Int32

The bitrate to use. The final bitrate can differ from the specified value.

targetFilename

String

The 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

WaveFormat

The input format, of the data to encode.

bitRate

Int32

The bitrate to use. The final bitrate can differ from the specified value.

targetStream

Stream

The 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 .

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom

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

WaveFormat

The input format, of the data to encode.

bitRate

Int32

The bitrate to use. The final bitrate can differ from the specified value.

targetFilename

String

The 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

WaveFormat

The input format, of the data to encode.

bitRate

Int32

The bitrate to use. The final bitrate can differ from the specified value.

targetStream

Stream

The 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 .

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom

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

WaveFormat

The input format, of the data to encode.

bitRate

Int32

The bitrate to use. The final bitrate can differ from the specified value.

targetFilename

String

The 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

Boolean

True 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

MediaFoundationEncoder

The encoder which should be used to encode the audio data.

source

IWaveSource

The IWaveSource which provides the raw audio data to encode.

CSCore.MediaFoundation.MediaFoundationEncoderEncodeWholeSourcewhile ((read = source.Read (buffer, 0, buffer.Length)) > 0)Writeend

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom

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

Guid

The audio subtype. For more information, see the AudioSubTypes class.

sampleRate

Int32

The requested sample rate.

channels

Int32

The requested number of channels.

bitRate

Int32

The 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

Guid

The 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.

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom

protected void SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)

Parameters

stream

Stream

Stream which should be used as the targetstream.

inputMediaType

MFMediaType

Mediatype of the raw input data to encode.

targetMediaType

MFMediaType

Mediatype of the encoded data.

containerType

Guid

Container type which should be used.

public void Write(Byte[] buffer, Int32 offset, Int32 count)

Parameters

buffer

Byte[]

A byte-array which contains raw data to encode.

offset

Int32

The zero-based byte offset in buffer at which to begin encoding bytes to the underlying stream.

count

Int32

The number of bytes to encode.

Properties

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; }

Class Diagram

public classMediaFoundationEncoderCreateAACEncoderCreateAACEncoderCreateMP3EncoderCreateMP3EncoderCreateWMAEncoderCreateWMAEncoderDisposeDisposeEncodeWholeSourceFinalizeFindBestMediaTypeGetEncoderMediaTypesSetTargetStreamWriteMediaFoundationEncoderEncodedDuration { get; }OutputMediaType { get; }SinkWriter { get; set; }TargetBaseStream { get; }TargetStream { get; set; }public interfaceIWriteableWritepublic interfaceIDisposablepublic classMediaFoundationExceptionTryMediaFoundationExceptionMediaFoundationExceptionpublic classMFAttributesCompareCompareItemCompareItemNativeCompareNativeCopyAllItemsCopyAllItemsNativeDeleteAllItemsDeleteAllItemsNativeDeleteItemDeleteItemNativeExistsGetGetGetAllocatedBlobNativeGetAllocatedStringNativeGetBlobGetBlobGetBlobNativeGetBlobSizeGetBlobSizeNativeGetCountGetCountNativeGetDoubleGetDoubleNativeGetGuidGetGuidNativeGetItemGetItemByIndexGetItemByIndexNativeGetItemNativeGetItemTypeGetItemTypeNativeGetStringGetStringLengthGetStringLengthNativeGetStringNativeGetUINT32GetUINT32NativeGetUINT64GetUINT64NativeGetUnknownNativeLockStoreLockStoreNativeSetSetSetBlobSetBlobNativeSetDoubleSetDoubleNativeSetGuidSetGuidNativeSetItemSetItemNativeSetStringSetStringNativeSetUINT32SetUINT32NativeSetUINT64SetUINT64NativeSetUnknownNativeUnlockStoreUnlockStoreNativeMFAttributesMFAttributesMFAttributesCount { get; }Item { get; set; }public classMFByteStreamBeginReadNativeBeginWriteNativeCloseCloseNativeDisposeEndReadNativeEndWriteNativeFlushFlushNativeGetCapabilitiesNativeGetCurrentPositionNativeGetLengthNativeIsEndOfStreamNativeReadReadNativeSeekSeekNativeSetCurrentPositionNativeSetLengthNativeWriteWriteNativeMFByteStreamMFByteStreamCapabilities { get; }CurrentPosition { get; set; }IsEndOfStream { get; }Length { get; set; }public classMFSinkWriterMF_SINK_WRITER_ALL_STREAMSMF_SINK_WRITER_MEDIASINKAddStreamAddStreamNativeBeginWritingBeginWritingNativeFinalizeWritingFinalizeWritingNativeFlushFlushNativeGetServiceForStreamGetServiceForStreamNativeGetStatisticsGetStatisticsNativeNotifyEndOfSegmentNotifyEndOfSegmentNativePlaceMarkerPlaceMarkerNativeSendStreamTickSendStreamTickNativeSetInputMediaTypeSetInputMediaTypeNativeWriteSampleWriteSampleNativeMFSinkWriterMFSinkWriterpublic classComObjectUnsafeBasePtrAddRefDisposeDisposeFinalizeQueryInterfaceQueryInterfaceQueryInterfaceReleaseComObjectComObjectBasePtr { get; set; }IsDisposed { get; }public classComStreamCloneCloseCommitCopyToDisposeFlushLockRegionReadReadRevertSeekSeekSetLengthSetSizeStatUnlockRegionWriteWriteComStreamCanRead { get; }CanSeek { get; }CanWrite { get; }Length { get; }Position { get; set; }

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom