Class FilterContext
Represents an instance of a filter within an FFmpeg filter graph.
Inheritance
Inherited Members
Namespace: FFmpeg.Filters
Assembly: FFmpeg.dll
Syntax
public class FilterContext : OptionQueryableBase, IOptionQueryable, ILoggingContext, IAVPointer<_AVFilterContext>, IBufferSource, IBufferSink
Remarks
A FilterContext stores the state of a filter after it has been added to a FilterGraph. It provides access to the filter's options, pads, links, and methods for sending or receiving frames from buffer source and sink filters.
Properties
View SourceExtraHWFrames
Gets or sets the number of additional hardware frames allocated by the filter.
Declaration
public int ExtraHWFrames { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
This property is primarily used with hardware-accelerated filters to reduce pipeline stalls caused by frame buffering.
Filter
Gets the filter associated with this context.
Declaration
public Filter Filter { get; }
Property Value
| Type | Description |
|---|---|
| Filter |
HwDeviceContext
Gets the hardware device context used by the filter.
Declaration
public DeviceContext_ref HwDeviceContext { get; }
Property Value
| Type | Description |
|---|---|
| DeviceContext_ref |
Remarks
Hardware-accelerated filters use this device context to determine the hardware device on which their operations are performed.
For filters such as HWUpload, the device context specifies the hardware device to which system-memory frames are uploaded unless the filter is configured to derive a device using its DeriveDevice property.
InputCount
Gets the number of input pads exposed by the filter.
Declaration
public uint InputCount { get; }
Property Value
| Type | Description |
|---|---|
| uint |
InputFilterLinks
Gets all connected input links.
Declaration
public IEnumerable<FilterLink> InputFilterLinks { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterLink> |
Remarks
Only connected input pads are included in the enumeration.
InputFilterPads
Gets an enumeration of all input pads.
Declaration
public IEnumerable<FilterPad> InputFilterPads { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterPad> |
Name
Gets the name of the filter context.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
OutputCount
Gets the number of output pads exposed by the filter.
Declaration
public uint OutputCount { get; }
Property Value
| Type | Description |
|---|---|
| uint |
OutputFilterLinks
Gets all connected output links.
Declaration
public IEnumerable<FilterLink> OutputFilterLinks { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterLink> |
Remarks
Only connected output pads are included in the enumeration.
OutputFilterPads
Gets an enumeration of all output pads.
Declaration
public IEnumerable<FilterPad> OutputFilterPads { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterPad> |
Pointer
Gets a pointer to the filter context, used for option queries.
Declaration
protected override void* Pointer { get; }
Property Value
| Type | Description |
|---|---|
| void* |
Overrides
View SourceThreads
Gets or sets the maximum number of worker threads used by the filter.
Declaration
public int Threads { get; set; }
Property Value
| Type | Description |
|---|---|
| int | A value less than or equal to zero lets FFmpeg choose the appropriate thread count automatically. |
Methods
View SourceAllocate(string, Filter, FilterGraph)
Allocates a filter context without initializing it.
Declaration
public static FilterContext? Allocate(string name, Filter filter, FilterGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
| Filter | filter | The filter to allocate. |
| FilterGraph | graph | The filter graph that will own the filter. |
Returns
| Type | Description |
|---|---|
| FilterContext | A newly allocated FilterContext, or null if the allocation failed. |
Remarks
Unlike Create(string, Filter, string?, FilterGraph), this method only allocates the filter context. Before the filter can be used, it must be initialized by calling one of the Init() overloads. This overload is useful when filter options must be configured before initialization.
As<T>()
Creates a managed wrapper of the specified filter context type for the current native filter context.
Declaration
public T As<T>() where T : FilterContext
Returns
| Type | Description |
|---|---|
| T | A managed wrapper of type |
Type Parameters
| Name | Description |
|---|---|
| T | The managed filter context type to create. |
Remarks
This method does not verify that the underlying native filter is compatible with
T. The caller is responsible for ensuring that the requested
type corresponds to the native filter context.
Exceptions
| Type | Condition |
|---|---|
| InvalidCastException |
|
Create(string, Filter, AVDictionary, FilterGraph)
Creates and initializes a filter using the specified dictionary of options.
Declaration
public static FilterContext Create(string name, Filter filter, AVDictionary dictionary, FilterGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
| Filter | filter | The filter to create. |
| AVDictionary | dictionary | The dictionary containing the filter options. |
| FilterGraph | graph | The filter graph that will own the filter. |
Returns
| Type | Description |
|---|---|
| FilterContext | The initialized FilterContext. |
Remarks
This method allocates the filter, applies the specified options during initialization, and returns the initialized filter context.
Create(string, Filter, AVMultiDictionary, FilterGraph)
Creates and initializes a filter using the specified multi-value dictionary of options.
Declaration
public static FilterContext Create(string name, Filter filter, AVMultiDictionary dictionary, FilterGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
| Filter | filter | The filter to create. |
| AVMultiDictionary | dictionary | The multi-value dictionary containing the filter options. |
| FilterGraph | graph | The filter graph that will own the filter. |
Returns
| Type | Description |
|---|---|
| FilterContext | The initialized FilterContext. |
Remarks
This method allocates the filter, initializes it using the specified options, and returns the initialized filter context.
Create(string, Filter, FilterGraph)
Creates and initializes a filter within the specified filter graph.
Declaration
public static FilterContext Create(string name, Filter filter, FilterGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
| Filter | filter | The filter to create. |
| FilterGraph | graph | The filter graph that will own the filter. |
Returns
| Type | Description |
|---|---|
| FilterContext | The initialized FilterContext. |
Remarks
Unlike Allocate(string, Filter, FilterGraph), this method both allocates and initializes the filter. After the method returns successfully, the filter is ready to be linked into a filter graph and used.
Create(string, Filter, IDictionary<string, string>, FilterGraph)
Creates and initializes a filter using the specified dictionary of options.
Declaration
public static FilterContext Create(string name, Filter filter, IDictionary<string, string> dictionary, FilterGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
| Filter | filter | The filter to create. |
| IDictionary<string, string> | dictionary | A dictionary containing the filter options. After the method returns, the dictionary contains only the options that were not recognized by the filter. |
| FilterGraph | graph | The filter graph that will own the filter. |
Returns
| Type | Description |
|---|---|
| FilterContext | The initialized FilterContext. |
Remarks
This method allocates the filter, initializes it using the specified options, and returns the initialized filter context.
Create(string, Filter, string?, FilterGraph)
Creates and initializes a filter within the specified filter graph.
Declaration
public static FilterContext Create(string name, Filter filter, string? args, FilterGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
| Filter | filter | The filter to create. |
| string | args | An optional filter argument string, or null to use the filter's default settings. |
| FilterGraph | graph | The filter graph that will own the filter. |
Returns
| Type | Description |
|---|---|
| FilterContext | The initialized FilterContext. |
Remarks
Unlike Allocate(string, Filter, FilterGraph), this method both allocates and initializes the filter. After the method returns successfully, the filter is ready to be linked into a filter graph and used.
Delete()
This frees the filter context and removes it from it's filter graph
Declaration
public void Delete()
GetInputFilterLink(int)
Gets the link connected to the specified input pad.
Declaration
public FilterLink? GetInputFilterLink(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based input pad index. |
Returns
| Type | Description |
|---|---|
| FilterLink | The connected FilterLink, or null if the input pad is not connected. |
GetInputFilterPad(int)
Gets the number of output pads exposed by the filter.
Declaration
public FilterPad GetInputFilterPad(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index |
Returns
| Type | Description |
|---|---|
| FilterPad |
GetOutputFilterLink(int)
Gets the link connected to the specified output pad.
Declaration
public FilterLink? GetOutputFilterLink(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based output pad index. |
Returns
| Type | Description |
|---|---|
| FilterLink | The connected FilterLink, or null if the output pad is not connected. |
GetOutputFilterPad(int)
Gets the output pad at the specified index.
Declaration
public FilterPad GetOutputFilterPad(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index |
Returns
| Type | Description |
|---|---|
| FilterPad |
Init()
Initializes the filter context without arguments.
Declaration
public AVResult32 Init()
Returns
| Type | Description |
|---|---|
| AVResult32 |
Init(AVDictionary)
Initializes the filter using the specified dictionary of options.
Declaration
public AVResult32 Init(AVDictionary dictionary)
Parameters
| Type | Name | Description |
|---|---|---|
| AVDictionary | dictionary | The dictionary containing the filter options. Recognized options are removed from the dictionary during initialization. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the initialization operation. |
Remarks
This method wraps FFmpeg's avfilter_init_dict(). Any options that are
not recognized by the filter remain in dictionary after
the method returns.
Init(AVMultiDictionary)
Initializes the filter using the specified dictionary of options.
Declaration
public AVResult32 Init(AVMultiDictionary dictionary)
Parameters
| Type | Name | Description |
|---|---|---|
| AVMultiDictionary | dictionary | The dictionary containing the filter options. Recognized options are removed from the dictionary during initialization. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the initialization operation. |
Remarks
This method wraps FFmpeg's avfilter_init_dict(). Any options that are
not recognized by the filter remain in dictionary after
the method returns.
Init(IDictionary<string, string>)
Initializes the filter using the specified dictionary of options.
Declaration
public AVResult32 Init(IDictionary<string, string> dictionary)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, string> | dictionary | A dictionary containing the filter options. After the method returns, the dictionary contains only the options that were not recognized by the filter. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the initialization operation. |
Remarks
If dictionary is an AVDictionary, it is
passed directly to FFmpeg. Otherwise, it is copied into a temporary
AVDictionary, and the remaining unrecognized options are copied
back into the original dictionary after initialization.
Init(string?)
Initializes the filter using an argument string.
Declaration
public AVResult32 Init(string? args)
Parameters
| Type | Name | Description |
|---|---|---|
| string | args |
Returns
| Type | Description |
|---|---|
| AVResult32 |
ToString()
Returns a string that identifies the filter context.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string containing the filter context name and filter name. |