Class ChannelLayout
Represents a channel layout, which defines the arrangement of audio channels in a multi-channel audio format. This class provides functionality to interact with and manipulate audio channel layouts using FFmpeg's FFmpeg.AutoGen._AVChannelLayout structure.
Implements
Inherited Members
Namespace: FFmpeg.Audio
Assembly: FFmpeg.dll
Syntax
public class ChannelLayout : IEquatable<ChannelLayout>, IChannelLayout, IEquatable<IChannelLayout>, IEquatable<ChannelLayout_ref>, IDisposable
Remarks
A channel layout describes the number and arrangement of audio channels (e.g., stereo, 5.1 surround sound). The ChannelLayout class allows you to create, initialize, and manage channel layouts, and to retrieve standard layouts available in FFmpeg.
Constructors
View SourceChannelLayout()
Initializes a new instance of the ChannelLayout class with no predefined layout.
Declaration
public ChannelLayout()
ChannelLayout(ulong)
Initializes a new instance of the ChannelLayout class using a channel mask.
Declaration
public ChannelLayout(ulong mask)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | mask | The channel mask used to initialize the layout. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the channel layout could not be initialized from the mask. |
Properties
View SourceChannels
Gets the number of channels in the current channel layout.
Declaration
public int Channels { get; }
Property Value
| Type | Description |
|---|---|
| int |
Mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC to signal non-diegetic channels. It is a bitmask, where the position of each set bit means that the AVChannel with the corresponding value is present.
Declaration
public ulong Mask { get; }
Property Value
| Type | Description |
|---|---|
| ulong |
Valid
Determines whether the current channel layout is valid.
Declaration
public bool Valid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
View SourceCopy()
Creates a deep copy of the current ChannelLayout object.
Declaration
public ChannelLayout Copy()
Returns
| Type | Description |
|---|---|
| ChannelLayout | A new ChannelLayout instance that is a deep copy of the current one. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown if there is insufficient memory to copy the channel layout. |
CreateDefault(int)
Creates a ChannelLayout instance using FFmpeg's default channel layout for the specified number of channels.
Declaration
public static ChannelLayout CreateDefault(int channels)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channels | The number of channels in the default layout. |
Returns
| Type | Description |
|---|---|
| ChannelLayout | A ChannelLayout representing FFmpeg's default layout for the specified channel count. |
Remarks
FFmpeg selects the default layout associated with the specified number of channels. For example, a channel count of 1 creates a mono layout, while a channel count of 2 creates a stereo layout.
CreateMono()
Creates a ChannelLayout instance representing a mono layout.
Declaration
public static ChannelLayout CreateMono()
Returns
| Type | Description |
|---|---|
| ChannelLayout | A ChannelLayout instance for a mono channel layout. |
CreateStereo()
Creates a ChannelLayout instance representing a stereo layout.
Declaration
public static ChannelLayout CreateStereo()
Returns
| Type | Description |
|---|---|
| ChannelLayout | A ChannelLayout instance for a stereo channel layout. |
CreateStereoDownMix()
Creates a ChannelLayout instance representing a stereo downmix layout.
Declaration
public static ChannelLayout CreateStereoDownMix()
Returns
| Type | Description |
|---|---|
| ChannelLayout | A ChannelLayout instance for a stereo downmix channel layout. |
CreateSurround()
Creates a ChannelLayout instance representing a surround sound layout.
Declaration
public static ChannelLayout CreateSurround()
Returns
| Type | Description |
|---|---|
| ChannelLayout | A ChannelLayout instance for a surround sound channel layout. |
Dispose()
Disposes of the resources used by the ChannelLayout, uninitializing the layout.
Declaration
public void Dispose()
Equals(ChannelLayout?)
Determines whether the current ChannelLayout is equal to another ChannelLayout.
Declaration
public bool Equals(ChannelLayout? other)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | other | The other ChannelLayout to compare with. |
Returns
| Type | Description |
|---|---|
| bool | true if the current layout is equal to the other layout; otherwise, false. |
Equals(ChannelLayout_ref)
Determines whether the current ChannelLayout is equal to another ChannelLayout_ref.
Declaration
public bool Equals(ChannelLayout_ref other)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout_ref | other | The other ChannelLayout_ref to compare with. |
Returns
| Type | Description |
|---|---|
| bool | true if the current layout is equal to the other layout; otherwise, false. |
Equals(IChannelLayout?)
Determines whether the current ChannelLayout is equal to another IChannelLayout.
Declaration
public bool Equals(IChannelLayout? other)
Parameters
| Type | Name | Description |
|---|---|---|
| IChannelLayout | other | The other IChannelLayout to compare with. |
Returns
| Type | Description |
|---|---|
| bool | true if the current layout is equal to the other layout; otherwise, false. |
Equals(object?)
Determines whether the current ChannelLayout is equal to another object.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool | true if the current instance is equal to the other object; otherwise, false. |
Overrides
View Source~ChannelLayout()
Declaration
protected ~ChannelLayout()
GetAllChannelLayouts()
Retrieves all standard channel layouts available in FFmpeg.
Declaration
public static IReadOnlyList<ChannelLayout> GetAllChannelLayouts()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ChannelLayout> | A read-only list of ChannelLayout objects representing the available layouts. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown when there is insufficient memory to copy a channel layout. |
GetCustomChannelId(int)
Gets the channel identifier for a channel in a custom channel layout.
Declaration
public AudioChannel GetCustomChannelId(int channelNumber)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channelNumber | The zero-based channel index. |
Returns
| Type | Description |
|---|---|
| AudioChannel | The channel identifier. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| InvalidOperationException | The channel layout is not a custom channel layout. |
GetCustomChannelName(int)
Gets the UTF-8 name of a channel in a custom channel layout.
Declaration
public string GetCustomChannelName(int channelNumber)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channelNumber | The zero-based channel index. |
Returns
| Type | Description |
|---|---|
| string | The channel name. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| InvalidOperationException | The channel layout is not a custom channel layout. |
GetHashCode()
Gets the hash code for the current ChannelLayout instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | The hash code for the current instance. |
Overrides
View SourceHasChannel(AudioChannel)
Determines whether the current channel layout contains the specified audio channel.
Declaration
public bool HasChannel(AudioChannel channelId)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioChannel | channelId | The channel identifier to search for. |
Returns
| Type | Description |
|---|---|
| bool | true if the specified channel is present in the layout; otherwise, false. |
Remarks
For custom channel layouts, this method searches the custom channel map. For native channel layouts, it checks whether the corresponding channel bit is set in the channel mask.
Init(int)
Initializes the current ChannelLayout with a custom number of channels.
Declaration
public void Init(int nb)
Parameters
| Type | Name | Description |
|---|---|---|
| int | nb | The number of channels to initialize the layout with. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown if memory allocation fails during initialization. |
| ArgumentException | Thrown if the number of channels provided is invalid. |
Parse(string)
Parses a ChannelLayout from a string representation.
Declaration
public static ChannelLayout Parse(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The string representation of the channel layout. |
Returns
| Type | Description |
|---|---|
| ChannelLayout | The parsed ChannelLayout. |
Remarks
This method is similar to TryParse(string, out ChannelLayout?) but throws an exception if parsing fails.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the string cannot be parsed into a valid channel layout. |
SetCustomChannelId(int, AudioChannel)
Sets the channel identifier for a channel in a custom channel layout.
Declaration
public void SetCustomChannelId(int channelNumber, AudioChannel channel)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channelNumber | The zero-based channel index. |
| AudioChannel | channel | The channel identifier. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| InvalidOperationException | The channel layout is not a custom channel layout. |
SetCustomChannelName(int, ReadOnlySpan<char>)
Sets the UTF-8 name of a channel in a custom channel layout.
Declaration
public void SetCustomChannelName(int channelNumber, ReadOnlySpan<char> name)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channelNumber | The zero-based channel index. |
| ReadOnlySpan<char> | name | The channel name. The encoded UTF-8 name must not exceed 16 bytes. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| ArgumentException |
|
| InvalidOperationException | The channel layout is not a custom channel layout. |
ToString()
Returns a string that represents the current ChannelLayout.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A description of the channel layout as a string, or an empty string if an error occurs. |
Overrides
View SourceTryParse(string, out ChannelLayout?)
Tries to parse a ChannelLayout from a string representation.
Declaration
public static bool TryParse(string str, out ChannelLayout? layout)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The string representation of the channel layout. |
| ChannelLayout | layout | When this method returns, contains the parsed ChannelLayout if the parse operation succeeded; otherwise, null. |
Returns
| Type | Description |
|---|---|
| bool |
Remarks
This method attempts to create a ChannelLayout from the given string.
If parsing is successful, the layout will contain the result; otherwise, it will be null.
Operators
View Sourceoperator ==(ChannelLayout?, ChannelLayout?)
Defines the equality operator for ChannelLayout instances.
Declaration
public static bool operator ==(ChannelLayout? left, ChannelLayout? right)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | left | The left ChannelLayout instance. |
| ChannelLayout | right | The right ChannelLayout instance. |
Returns
| Type | Description |
|---|---|
| bool |
operator ==(ChannelLayout?, ChannelLayout_ref)
Defines the equality operator for ChannelLayout and ChannelLayout_ref instances.
Declaration
public static bool operator ==(ChannelLayout? left, ChannelLayout_ref right)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | left | The ChannelLayout instance. |
| ChannelLayout_ref | right | The ChannelLayout_ref instance. |
Returns
| Type | Description |
|---|---|
| bool |
operator ==(ChannelLayout?, IChannelLayout?)
Defines the equality operator for ChannelLayout and IChannelLayout instances.
Declaration
public static bool operator ==(ChannelLayout? left, IChannelLayout? right)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | left | The ChannelLayout instance. |
| IChannelLayout | right | The IChannelLayout instance. |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(ChannelLayout?, ChannelLayout?)
Defines the inequality operator for ChannelLayout instances.
Declaration
public static bool operator !=(ChannelLayout? left, ChannelLayout? right)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | left | The left ChannelLayout instance. |
| ChannelLayout | right | The right ChannelLayout instance. |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(ChannelLayout?, ChannelLayout_ref)
Defines the inequality operator for ChannelLayout and ChannelLayout_ref instances.
Declaration
public static bool operator !=(ChannelLayout? left, ChannelLayout_ref right)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | left | The ChannelLayout instance. |
| ChannelLayout_ref | right | The ChannelLayout_ref instance. |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(ChannelLayout?, IChannelLayout?)
Defines the inequality operator for ChannelLayout and IChannelLayout instances.
Declaration
public static bool operator !=(ChannelLayout? left, IChannelLayout? right)
Parameters
| Type | Name | Description |
|---|---|---|
| ChannelLayout | left | The ChannelLayout instance. |
| IChannelLayout | right | The IChannelLayout instance. |
Returns
| Type | Description |
|---|---|
| bool |