Class FilterGraph
Represents a filter graph that contains a collection of connected filters.
Inherited Members
Namespace: FFmpeg.Filters
Assembly: FFmpeg.dll
Syntax
public sealed class FilterGraph : ILoggingContext, IDisposable, IAVPointer<_AVFilterGraph>
Remarks
A FilterGraph owns the FilterContext instances created within it and manages the links between them. Once configured, the graph can be used to process audio or video frames.
Properties
View SourceCount
Gets the number of filters contained in the graph.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Filters
Gets a read-only list view over all filters contained in the graph.
Declaration
public IReadOnlyList<FilterContext> Filters { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<FilterContext> |
InputFilters
Gets all buffer source filters contained in the graph.
Declaration
public IEnumerable<FilterContext> InputFilters { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterContext> |
Remarks
These are the filters that provide input frames to the graph.
this[int]
Gets the filter at the specified index.
Declaration
public FilterContext this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the filter. |
Property Value
| Type | Description |
|---|---|
| FilterContext | The FilterContext at the specified index. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
OutputFilters
Gets all buffer sink filters contained in the graph.
Declaration
public IEnumerable<FilterContext> OutputFilters { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterContext> |
Remarks
These are the filters that receive processed output frames from the graph.
SinkFilters
Gets all sink filters contained in the graph.
Declaration
public IEnumerable<FilterContext> SinkFilters { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterContext> |
Remarks
Sink filters have no output pads and consume media from the graph.
SourceFilters
Gets all source filters contained in the graph.
Declaration
public IEnumerable<FilterContext> SourceFilters { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterContext> |
Remarks
Source filters have no input pads and generate media for the graph.
Threads
Gets or sets the maximum number of threads used when processing the filter graph.
Declaration
public int Threads { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
A value of 0 allows FFmpeg to choose an appropriate number of threads.
UnlinkedInFilters
Gets all filters that have at least one unconnected input pad.
Declaration
public IEnumerable<FilterContext> UnlinkedInFilters { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterContext> |
UnlinkedOutFilters
Gets all filters that have at least one unconnected output pad.
Declaration
public IEnumerable<FilterContext> UnlinkedOutFilters { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<FilterContext> |
Methods
View SourceAllocate()
Allocates a new, empty filter graph.
Declaration
public static FilterGraph Allocate()
Returns
| Type | Description |
|---|---|
| FilterGraph | A new unconfigured FilterGraph instance. |
Remarks
Unlike the Create methods, this method only allocates the filter graph.
No filters are created or parsed.
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | FFmpeg was unable to allocate the filter graph. |
Config()
Validates and configures all links in the filter graph.
Declaration
public AVResult32 Config()
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the configuration operation. |
Remarks
This method should be called after all filters have been created and linked, and before frames are processed through the graph.
Copy()
Creates a unconfigured copy of the filter graph.
Declaration
public FilterGraph Copy()
Returns
| Type | Description |
|---|---|
| FilterGraph | A new FilterGraph containing equivalent filters and connections. |
Remarks
The copied graph contains newly allocated filter contexts configured with the same options and topology as the original graph. There is not ffmpeg function. This function tries to recreate the filter graph with the same paramters. Buffer sinks and filter contexts named auto_* are not configured.
Create(out FilterInOutList?, string, out FilterInOutList?)
Creates a filter graph from the specified filter graph description.
Declaration
public static FilterGraph Create(out FilterInOutList? inputs, string filter, out FilterInOutList? outputs)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterInOutList | inputs | When this method returns, contains any unlinked input endpoints remaining after parsing. |
| string | filter | The FFmpeg filter graph description to parse. |
| FilterInOutList | outputs | When this method returns, contains any unlinked output endpoints remaining after parsing. |
Returns
| Type | Description |
|---|---|
| FilterGraph | The newly created FilterGraph. |
Remarks
This overload preserves any unlinked input and output endpoints returned by FFmpeg, allowing them to be connected later.
Exceptions
| Type | Condition |
|---|---|
| FFmpegException | Thrown if the filter graph could not be parsed. |
Create(string)
Creates a filter graph from the specified filter graph description.
Declaration
public static FilterGraph Create(string filter)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filter | The FFmpeg filter graph description to parse. |
Returns
| Type | Description |
|---|---|
| FilterGraph | The newly created and parsed FilterGraph. |
Remarks
This method parses the supplied filter graph description using
avfilter_graph_parse_ptr(). Any unlinked inputs or outputs are
discarded. Use Create(out FilterInOutList?, string, out FilterInOutList?)
if access to unlinked endpoints is required.
Exceptions
| Type | Condition |
|---|---|
| FFmpegException | Thrown if the filter graph could not be parsed. |
Dispose()
Releases all resources used by this FilterGraph instance.
Declaration
public void Dispose()
Dump()
Returns a textual representation of the current filter graph.
Declaration
public string Dump()
Returns
| Type | Description |
|---|---|
| string | A human-readable description of the graph. |
Remarks
This method is primarily intended for debugging and diagnostics.
~FilterGraph()
Finalizer for the FilterGraph class.
Declaration
protected ~FilterGraph()
FindFilter(string)
Finds a filter by its instance name.
Declaration
public FilterContext? FindFilter(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the filter instance. |
Returns
| Type | Description |
|---|---|
| FilterContext | The matching filter, or null if no filter with the specified name exists. |
Flush()
Creates a copy of the filter graph and disposed the old one.
Declaration
public void Flush()
GetEnumerator()
Returns an enumerator that iterates through the filters in the graph.
Declaration
public IEnumerator<FilterContext> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<FilterContext> | An enumerator over the graph's filters. |
Insert(FilterLink, FilterContext, int, int)
Inserts a filter into an existing link between two filters.
Declaration
public AVResult32 Insert(FilterLink link, FilterContext filter, int srcFilterPad, int destFilterPad)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterLink | link | The link to split. |
| FilterContext | filter | The filter to insert. |
| int | srcFilterPad | The output pad index on the inserted filter. |
| int | destFilterPad | The input pad index on the inserted filter. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the insertion operation. |
Link(FilterContext, FilterContext)
Connects the first output pad of one filter to the first input pad of another filter.
Declaration
public AVResult32 Link(FilterContext src, FilterContext dst)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterContext | src | The source filter. |
| FilterContext | dst | The destination filter. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the link operation. |
Link(FilterContext, int, FilterContext, int)
Connects an output pad of one filter to an input pad of another filter.
Declaration
public AVResult32 Link(FilterContext src, int srcpad, FilterContext dst, int dstpad)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterContext | src | The source filter. |
| int | srcpad | The zero-based output pad index on |
| FilterContext | dst | The destination filter. |
| int | dstpad | The zero-based input pad index on |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the link operation. |
Parse(out FilterInOutList, string, out FilterInOutList)
Parses a filter graph description without linking it to existing filters.
Declaration
public AVResult32 Parse(out FilterInOutList inputs, string filters, out FilterInOutList outputs)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterInOutList | inputs | When this method returns, contains the unconnected input filters. |
| string | filters | The filter graph description. |
| FilterInOutList | outputs | When this method returns, contains the unconnected output filters. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the parse operation. |
Remarks
This method wraps FFmpeg's avfilter_graph_parse2().
ParseAndLink(FilterInOutList?, string, FilterInOutList?)
Parses a filter graph description and connects it to the specified input and output filters.
Declaration
public AVResult32 ParseAndLink(FilterInOutList? input, string filters, FilterInOutList? output)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterInOutList | input | The input filter list, or null if no explicit input list should be supplied. |
| string | filters | The filter graph description. |
| FilterInOutList | output | The output filter list, or null if no explicit output list should be supplied. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the parse operation. |
Remarks
This method wraps FFmpeg's avfilter_graph_parse_ptr(). Any unconnected
inputs or outputs remaining after parsing are written back into the supplied
FilterInOutList instances.
ParseAndLink(out FilterInOutList, string, out FilterInOutList)
Parses a filter graph description and returns any unconnected inputs and outputs.
Declaration
public AVResult32 ParseAndLink(out FilterInOutList input, string filters, out FilterInOutList output)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterInOutList | input | When this method returns, contains the unconnected input filters. |
| string | filters | The filter graph description. |
| FilterInOutList | output | When this method returns, contains the unconnected output filters. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the parse operation. |
Remarks
This method wraps FFmpeg's avfilter_graph_parse_ptr().
TryCreate(out FilterInOutList?, string, out FilterInOutList?, out FilterGraph?)
Attempts to create a FilterGraph by parsing the specified FFmpeg filter graph description.
Declaration
public static AVResult32 TryCreate(out FilterInOutList? inputs, string filter, out FilterInOutList? outputs, out FilterGraph? filterGraph)
Parameters
| Type | Name | Description |
|---|---|---|
| FilterInOutList | inputs | When this method returns successfully, contains the collection of unlinked input endpoints remaining after parsing the filter graph; otherwise, null. |
| string | filter | The FFmpeg filter graph description to parse. |
| FilterInOutList | outputs | When this method returns successfully, contains the collection of unlinked output endpoints remaining after parsing the filter graph; otherwise, null. |
| FilterGraph | filterGraph | When this method returns successfully, contains the newly created FilterGraph; otherwise, null. |
Returns
| Type | Description |
|---|---|
| AVResult32 |
|
Remarks
This method allocates a new FilterGraph and parses the
specified filter graph description using FFmpeg. Any filter endpoints that
are not connected during parsing are returned through
inputs and outputs so they can be
linked manually.
TryCreate(string, out FilterGraph?)
Attempts to create a filter graph from the specified filter graph description.
Declaration
public static AVResult32 TryCreate(string filter, out FilterGraph? graph)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filter | The FFmpeg filter graph description to parse. |
| FilterGraph | graph | When this method returns successfully, contains the created FilterGraph; otherwise, null. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result of the parse operation. |
Remarks
This overload parses the graph description but discards any unlinked input or output endpoints. Use TryCreate(out FilterInOutList?, string, out FilterInOutList?, out FilterGraph?) if access to those endpoints is required.