Struct Codec
Represents an FFmpeg codec descriptor. This structure provides managed access to the underlying native FFmpeg.AutoGen._AVCodec structure, exposing codec information, capabilities, and supported encoding/decoding configurations.
Implements
Inherited Members
Namespace: FFmpeg.Codecs
Assembly: FFmpeg.dll
Syntax
public readonly struct Codec : IEquatable<Codec>
Remarks
A Codec instance does not own the underlying FFmpeg codec. The referenced codec descriptor is managed internally by FFmpeg and must not be freed manually.
Properties
View SourceCapabilities
Gets the capabilities of the codec, represented by a set of flags indicating what the codec supports. These capabilities can include features such as hardware acceleration, variable frame rates, or support for certain compression techniques.
Declaration
public CodecCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| CodecCapabilities |
ChannelLayouts
Gets the channel layouts supported by the codec. A channel layout describes the arrangement of audio channels, such as mono, stereo, or surround configurations.
Declaration
public ChannelLayoutConstList ChannelLayouts { get; }
Property Value
| Type | Description |
|---|---|
| ChannelLayoutConstList |
Remarks
This information is only available for audio codecs that expose supported channel configurations.
CodecID
Gets the codec ID, which uniquely identifies the codec within the FFmpeg framework. The codec ID is used to match the codec with the corresponding media stream format or container, ensuring correct decoding or encoding.
Declaration
public CodecID CodecID { get; }
Property Value
| Type | Description |
|---|---|
| CodecID |
IsDecoder
Gets a value indicating whether this codec can be used for decoding.
Declaration
public bool IsDecoder { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Decoder codecs consume compressed packets and produce raw frames.
IsEncoder
Gets a value indicating whether this codec can be used for encoding.
Declaration
public bool IsEncoder { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Encoder codecs consume raw frames and produce compressed packets.
LongName
Gets the human-readable, descriptive name of the codec (e.g., "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"). This name is more verbose than Name and provides better clarity for end users.
Declaration
public string LongName { get; }
Property Value
| Type | Description |
|---|---|
| string |
MaxLowResolution
Gets the maximum low-resolution decoding level supported by the codec. Higher values indicate that the decoder can operate on progressively lower resolution versions of the encoded stream.
Declaration
public byte MaxLowResolution { get; }
Property Value
| Type | Description |
|---|---|
| byte |
MediaType
Gets the media type of the codec (e.g., video, audio, subtitle). This value indicates the kind of media data that the codec handles, allowing it to be categorized appropriately in multimedia processing workflows.
Declaration
public MediaType MediaType { get; }
Property Value
| Type | Description |
|---|---|
| MediaType |
Name
Gets the short, symbolic name of the codec implementation (e.g., "h264", "aac"). This name is typically used in code or configuration files to reference the codec.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Profiles
Gets the array of recognized profiles for the codec. Each profile defines a set of features or capabilities that the codec can use during encoding or decoding. This array lists the profiles that the codec supports, allowing you to choose the appropriate one for your use case.
Declaration
public ReadOnlyCollection<Profile> Profiles { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlyCollection<Profile> |
SupportedFramerates
Gets the array of supported framerates for the codec. The framerates represent the possible frame-per-second (FPS) values that the codec can handle. These values are returned as an array of rational numbers, allowing precise representation of fractional framerates.
Declaration
public ReadOnlySpan<Rational> SupportedFramerates { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlySpan<Rational> |
SupportedPixelFormats
Gets the array of supported pixel formats for the codec. This array defines the pixel formats the codec can encode or decode, which control how the image data is represented (e.g., RGB, YUV, etc.).
Declaration
public ReadOnlySpan<PixelFormat> SupportedPixelFormats { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlySpan<PixelFormat> |
SupportedSampleFormats
Gets the array of supported audio sample formats for the codec. The sample formats specify how audio data is represented in memory (e.g., signed 16-bit, floating point, planar, etc.), and this array lists all formats that the codec can process.
Declaration
public ReadOnlySpan<SampleFormat> SupportedSampleFormats { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlySpan<SampleFormat> |
SupportedSampleRates
Gets the array of supported audio sample rates for the codec. These are the sample rates (in Hz) that the codec supports for audio processing, which determine the frequency at which audio data is captured or played back.
Declaration
public ReadOnlySpan<int> SupportedSampleRates { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlySpan<int> |
WrapperName
Gets the group name of the codec implementation. This is a short, symbolic name that identifies the codec's wrapper or implementation, such as a specific library or framework backing the codec. If the field is null, the codec is native to FFmpeg.
Declaration
public string? WrapperName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
View SourceEquals(Codec)
Determines whether the specified Codec is equal to the current instance. Two Codec instances are considered equal if they reference the same underlying FFmpeg codec.
Declaration
public bool Equals(Codec other)
Parameters
| Type | Name | Description |
|---|---|---|
| Codec | other | The Codec to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool | true if the specified Codec is equal to the current instance; otherwise, false. |
Equals(object?)
Determines whether the specified object is equal to the current Codec instance. Two Codec instances are considered equal if they reference the same underlying FFmpeg codec.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current Codec. |
Returns
| Type | Description |
|---|---|
| bool | true if the specified object is equal to the current instance; otherwise, false. |
Overrides
View SourceFindDecoder(CodecID)
Finds a decoder by its codec ID.
This method searches for a decoder codec that matches the provided codecID.
Declaration
public static Codec? FindDecoder(CodecID codecID)
Parameters
| Type | Name | Description |
|---|---|---|
| CodecID | codecID | The codec ID that uniquely identifies the desired decoder. |
Returns
| Type | Description |
|---|---|
| Codec? | An instance of Codec representing the decoder if found; otherwise, null. |
FindDecoder(string)
Finds a decoder by its name. This method searches for a decoder codec by its symbolic name (e.g., "h264" for an H.264 decoder).
Declaration
public static Codec? FindDecoder(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The symbolic name of the decoder codec to search for. |
Returns
| Type | Description |
|---|---|
| Codec? | An instance of Codec representing the decoder if found; otherwise, null. |
FindEncoder(CodecID)
Finds an encoder by its codec ID.
This method searches for an encoder codec that matches the provided codecID.
Declaration
public static Codec? FindEncoder(CodecID codecID)
Parameters
| Type | Name | Description |
|---|---|---|
| CodecID | codecID | The codec ID that uniquely identifies the desired encoder. |
Returns
| Type | Description |
|---|---|
| Codec? | An instance of Codec representing the encoder if found; otherwise, null. |
FindEncoder(string)
Finds an encoder by its name. This method searches for an encoder codec by its symbolic name (e.g., "aac" for an AAC encoder).
Declaration
public static Codec? FindEncoder(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The symbolic name of the encoder codec to search for. |
Returns
| Type | Description |
|---|---|
| Codec? | An instance of Codec representing the encoder if found; otherwise, null. |
GetAllCodecs()
Retrieves a list of all available codecs, including both encoders and decoders. This method iterates through all registered codecs in FFmpeg and returns them as Codec instances.
Declaration
public static ReadOnlyCollection<Codec> GetAllCodecs()
Returns
| Type | Description |
|---|---|
| ReadOnlyCollection<Codec> | A read-only collection of Codec instances representing all registered codecs. |
GetBestPixelFormat(PixelFormat)
Determines the most suitable pixel format supported by this codec for converting from the specified source pixel format.
Declaration
public PixelFormat GetBestPixelFormat(PixelFormat src)
Parameters
| Type | Name | Description |
|---|---|---|
| PixelFormat | src | The source pixel format to convert from. |
Returns
| Type | Description |
|---|---|
| PixelFormat | The best supported pixel format for the conversion, or None if no suitable format is available. |
GetBestPixelFormat(PixelFormat, out FFLoss)
Determines the most suitable pixel format supported by this codec for converting from the specified source pixel format.
Declaration
public PixelFormat GetBestPixelFormat(PixelFormat src, out FFLoss loss)
Parameters
| Type | Name | Description |
|---|---|---|
| PixelFormat | src | The source pixel format to convert from. |
| FFLoss | loss | Receives the information about quality losses introduced by the conversion. |
Returns
| Type | Description |
|---|---|
| PixelFormat | The best supported pixel format for the conversion, or None if no suitable format is available. |
GetBestPixelFormat(PixelFormat, bool)
Determines the most suitable pixel format supported by this codec for converting from the specified source pixel format.
Declaration
public PixelFormat GetBestPixelFormat(PixelFormat src, bool alphaUsed)
Parameters
| Type | Name | Description |
|---|---|---|
| PixelFormat | src | The source pixel format to convert from. |
| bool | alphaUsed | Indicates whether the alpha channel must be preserved when selecting a format. |
Returns
| Type | Description |
|---|---|
| PixelFormat | The best supported pixel format for the conversion, or None if no suitable format is available. |
GetBestPixelFormat(PixelFormat, bool, out FFLoss)
Determines the most suitable pixel format supported by this codec for converting from the specified source pixel format.
Declaration
public PixelFormat GetBestPixelFormat(PixelFormat src, bool alphaUsed, out FFLoss loss)
Parameters
| Type | Name | Description |
|---|---|---|
| PixelFormat | src | The source pixel format to convert from. |
| bool | alphaUsed | Indicates whether the alpha channel must be preserved when selecting a format. |
| FFLoss | loss | Receives the information about quality losses introduced by the conversion. |
Returns
| Type | Description |
|---|---|
| PixelFormat | The best supported pixel format for the conversion, or None if no suitable format is available. |
GetHashCode()
Returns a hash code for the current Codec instance, based on the memory pointer of the underlying FFmpeg codec structure.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for the current Codec instance. |
Overrides
View SourceToString()
Returns a string representation of the current Codec instance, including the codec's symbolic name, descriptive name, and codec ID.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of the codec with its name, long name, and codec ID. |
Overrides
Operators
View Sourceoperator ==(Codec, Codec)
Determines whether two Codec instances are equal by comparing their underlying codec structures.
Declaration
public static bool operator ==(Codec left, Codec right)
Parameters
| Type | Name | Description |
|---|---|---|
| Codec | left | The first Codec to compare. |
| Codec | right | The second Codec to compare. |
Returns
| Type | Description |
|---|---|
| bool | true if the two Codec instances are equal; otherwise, false. |
operator !=(Codec, Codec)
Determines whether two Codec instances are not equal by comparing their underlying codec structures.
Declaration
public static bool operator !=(Codec left, Codec right)
Parameters
| Type | Name | Description |
|---|---|---|
| Codec | left | The first Codec to compare. |
| Codec | right | The second Codec to compare. |
Returns
| Type | Description |
|---|---|
| bool | true if the two Codec instances are not equal; otherwise, false. |