FFmpeg Document 32-filter Chain Diagram Introduction

Source: Internet
Author: User
Tags drawtext alphanumeric characters

Filter Chain Diagram Introduction

A filter chain diagram (filtergraph) is a forward graph of the connection filter. It can include a looping action, or a link between multiple filters, each with an input connected to the filter and an output connected to the filter.

Each filter in the filter chain is an instance of the filter registration class application, which defines the filter's function, input interface, and output interface.

If the filter has no input (interface), it is called "source", if the filter does not have an output end is called "slot" (such a filter used to describe/test the scene, rather than the actual processing)

Filter Chain diagram syntax

Filter chain diagrams are text-based, with options that are common to some ffmpeg and Ffplay-filter/-vf/-afAnd-filter_complex(FFmpeg) and-vf/-af(Ffplay) plus definitions andlibavfilter/avfilter.hOfavfilter_graph_parse_ptr()And so on to describe.

A filter chain contains a series of linked filters, which are separated by "," to describe each filter

A filter chain chart contains the sequence filter chain, which has ";" to separate each filter chain description

A filter is represented by a single string form:[in_link_1]...[in_link_N]filter_name=arguments[out_link_1]...[out_link_M]

here filter_name is the filter class name that specifies the filter instance (which is registered in the program). Thereafter the =arguments is used to specify filter options. arguments is the parameter used to initialize the filter, which may have one of the following two types of forms:

  • A ":" Delimited key=value list

  • A ":" Delimited listvalueValue, in which case the key (key) is assumed to be the order of the option name Declaration, asfadeThe filter declares 3 options sequentiallytypestart_frameAndnb_frames, the parameterin:0:30means thetypeForinstart_frameFor0nb_framesFor30

  • A mixture of the preceding two. In this case, the key-value pairs must be in front, followed by several values that follow the same constraints. In key-value pairs, you can set precedence in any order. (The next value is set by the last key value pair in the order continuation).

If the value of an option is itself a list (for example format , a filter has a list of pixel formatting options), this list is usually used with the "|" Separated.

list parameters can be Code style= "BORDER:0; border-radius:4px; font-size:90%; Background-color: #d6dbdf; Color: #2c3e50; padding-top:2px; padding-right:4px; padding-bottom:2px; padding-left:4px; " > ' (single quote) included. Character \ is used as an escape character to enclose text in quotation marks. Otherwise, the parameter string is considered terminated when it encounters a special character (for example, ' []=; ').

There is a list of connection labels before and after the filter name and parameters. A connection tag allows a 1-name connection to be named as the input or output port of the filter. The following booking label is used as the input of the in_link_1 ... in_link_N filter, out_link_1 ... out_link_M as the output of the filter.

When a connection label of the same name is found in one of the filter chains, a connection between the corresponding input and output is created (that is, it is considered to be connected, if it is used as the output of one filter and the input of a filter, the previous filter is output to the latter one)

If an output does not have a named label, it is connected by default to the first input on a filter chain that has no named label in the filter. For example:

nullsrc, split[L1], [L2]overlay, nullsink

Over heresplitThere are two outputs,overlayThere are two inputs,splitThe first output is named label "L1",overlayThe first input is named label "L2". ThesplitThe second output is linked to theoverlaySecond input (they are not named with a label).

In a filter description, if the input of the first filter is not specified, it is assumed to be "in" and is assumed to be "out" if the last filter output is not specified

On a complete filter chain, all untagged named inputs and outputs must be connected (matched). The filter chain diagram is considered valid if both the input and output of all the filters are connected.

libavfilter will automatically insert scale filter. For the filter chain diagram description, can be through sws_flags=flags to specify swscale flag enables automatic insertion and contraction.

Here is a BNF description of the filter chain diagram syntax:

NAME ::= sequence of alphanumeric characters and ‘_‘LINKLABEL::= "[" NAME "]"LINKLABELS   ::= LINKLABEL [LINKLABELS]FILTER_ARGUMENTS ::= sequence of chars (possibly quoted)FILTER   ::= [LINKLABELS] NAME ["=" FILTER_ARGUMENTS] [LINKLABELS]FILTERCHAIN  ::= FILTER [,FILTERCHAIN]FILTERGRAPH  ::= [sws_flags=flags;] FILTERCHAIN [;FILTERGRAPH]
Notice the escape in the filter chain diagram

Filter chain elements need to contain multiple layers of escaping. Refer to the "References and escapes" section of the Ffmpeg-utils (1) Manual ("quoting and escaping") For more information about the escape process.

The escape effect of the first layer in each filter option value, it may contain a special character ":" To separate the value, or an escape character ""

The second layer of escaping is described in the entire filter, which may contain escape characters "" or special characters "[];", which are used for the description of the filter chain diagram

In fact, you may also encounter the escape of the third layer when you describe the filter chain diagram on the shell command line (handling characters that need to be escaped in the shell)

For example, the following character needs to embed drawtext the value of the filter description text

this is a ‘string‘: may contain one, or more, special characters

This string contains characters that need to be escaped, and : here it also needs to be escaped, by:

text=this is a \‘string\‘\: may contain one, or more, special characters

When embedding the filter description, a second layer of escape occurs, in order to escape all the filter chain special characters, you need to follow the example processing:

drawtext=text=this is a \\\‘string\\\‘\\: may contain one\, or more\, special characters

( note that each special character in the escape needs to be escaped again, it becomes a \ ')

Finally, it is escaped again when the filter chain is written on the shell command line. For example, you need to escape each special character and escape processing \ , and ultimately:

-vf "drawtext=text=this is a \\\\\\‘string\\\\\\‘\\\\: may contain one\\, or more\\, special characters"

FFmpeg Document 32-filter Chain Diagram Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.