"Ffmpeg basics" Chinese version - 13. Mathematical Functions

13. Mathematical Functions

FFmpeg One advantage is that it provides a lot of built-in mathematical functions, we can use them in a number of audio and video filter, option or source, which provides great convenience for our work.

Use mathematical functions in expressions

FFmpeg Many options require a numeric value, and the values ​​may be represented in the form of an expression, the expression can contain numbers, numeric operators (+ - * / etc), constants, and mathematical functions built FFmpeg. Photos of some specific function is generally used for audio and video Sources filter (filter is, video sources, audio sources, etc., they are generally not need to enter, but may output specific data, such as the color is a video source, it can be a solid color output ) used in conjunction with, the following table lists the Filter function can be used, option, sources, and a detailed description of how to find them.

In order to evaluate a mathematical expression in FFmpeg, which provides a formula evaluator relevant Internally, this program is to document libavutil / eval.h of interface implementation. Programs using the International System number prefixes (prefix number international norms) (it is called in the FFmpeg suffix postfixes, because it closely follows, in digital). If a plus i, it uses the n-th power of 2, after the prefix, instead of the n-th power of 10. B This prefix indicates that the value is multiplied by 8, he and other prefixes used in conjunction, can be used alone, means that we can use as B, KB, prefixes such MiB. SI number prefixes that can be used are described in the first chapter, "the FFmpeg base" in the. C language developers can automatically expand the list of unary and binary functions (i.e., two parameters and a parameter), and the additional constant may be defined, so that they can be used in expressions.

Here Insert Picture Description

Built-in mathematical operators

FFmpeg user may use common mathematical unary and binary operators, is described as follows:

Here Insert Picture Description

Built-in constants

Current, FFmpeg contains only the following three constants, but developers can define additional constants by modifying the source code:

Here Insert Picture Description

PI constants are often used in trigonometric functions such as sine, cosine, tangent, etc. For example, you want to use 523.251 Hz tone to generate a C5, we can use the command:

ffplay -f lavfi -i aevalsrc=sin(523.251*2*PI*t)

Since sin and cos of the same periodicity, the following command and said command same result:

ffplay -f lavfi -i aevalsrc=cos(523.251*2*PI*t)

Built-in math functions table

If we use two different expressions, but they want to express it is an expression, then we can use the following form: "expr1; expr2", this time in turn expr1 and expr2 calculated in accordance with the order, and the new expression the formula returns the value of the last expression, that is the result of expr2.

When the integer expression should be expressed as a Boolean value, nonzero if true, 0 represents false. For logic value, we can use the * sign as a logical AND, + the symbol for a logical OR.

The following is FFmpeg all available functions:

Here Insert Picture Description

Here Insert Picture Description

Use cases function

Function can be widely used drawtext filter. E.g. lt (x, y) and gt (x, y) function is used to set the text display on the video frame or disappear time, e.g., 5 seconds delay text:

ffplay -f lavfi -i color=c=orange -vf drawtext=fontfile=/Windows/Fonts/arial.ttf:fontcolor=white:fontsize=20:text="5 seconds delayed text":x=(w-tw)/2:y=(h-th)/2:draw=gt(t\,5)

Other examples in this book about the function:

  • "Add text on the video."
  • "Digital Audio"
  • "Batch processing"
H&A
Released seven original articles · won praise 4 · Views 820

Guess you like

Origin blog.csdn.net/qq_34305316/article/details/103937521