SciTech-AV-Video-DVP(Digital Video Processing)-CV/CG-ffmpeg-libavfilter:数字过滤器-
This document describes filters, sources, and sinks provided by the libavfilter library.
Filtergraph Syntax
- Filters in the same linear chain
are separated bycommas, - distinct linear chains of filters
are separated bysemicolons. - The points where the linear chains join are labelled by names
enclosed insquare brackets. - Some filters
take in inputa list of parameters:they are specifiedafter the filter name and an equal sign,they are separated from each otherby a colon.
- There exist so-called:
- source filters that
do not havean audio/video input, - sink filters that
will not haveaudio/video output.
- source filters that
Filtering Introduction
Filtering in FFmpeg is enabled through the libavfilter library.
In libavfilter, a filter can have multiple inputs and multiple outputs.
To illustrate the sorts of things that are possible, we consider the following filtergraph.
Example of filtergraph:
[main]
input --> split ---------------------> overlay --> output
| ^
|[tmp] [flip]|
+-----> crop --> vflip -------+
This filtergraph splits the input stream in two streams, then,
sends one stream through the crop filter and the vflip filter,
before merging it back with the other stream by overlaying it on top.
You can use the following command to achieve this:
ffmpeg -i INPUT -vf "split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2" OUTPUT
The result will be that the top half of the video is mirrored onto the bottom half of the output video.
In our example,
- crop,vflip are in one linear chain,
- split and overlay are separately in another.
- the split filter generates two outputs that are associated to the labels [main] and [tmp].
- the stream sent to the second output of split, labelled as [tmp], is processed through the crop filter.
- the crop filter crops away the lower half part of the video, and then vertically flipped.
- The overlay filter takes in input the first unchanged output of the split filter (which was labelled as [main]), and overlay on its lower half the output generated by the crop, vflip filterchain.
# 4.1 Filtergraph syntax
A filtergraph has a textual representation, which:
* is recognized by:
- the `-filter/-vf/-af` and `-filter_complex` **options in ffmpeg**
- `-vf/-af` in ffplay
* and by **the avfilter_graph_parse_ptr() function** `defined in` `libavfilter/avfilter.h`.
- A filterchain
consists ofa sequence of connected filters, each oneconnected tothe previous one in the sequence. - A filterchain is represented by a list of
","-separatedfilter descriptions. - A filtergraph
consists ofa sequence of filterchains. - A sequence of filterchains
is represented bya list of";"-separatedfilterchain descriptions. - A filter
is represented bya string of the form:[in_link_1]...[in_link_N]filter_name@id=arguments[out_link_1]...[out_link_M]
filter_name:- is the name of the filter class of which the described filter is an instance of,
- and
has to bethe name of one of the filter classesregistered in the program optionally followedby"@id". - The name of the filter class
is optionally followed by** a string**"=arguments
arguments is a string which contains the parameters used to initialize the filter instance.
It may have one of two forms:
- A
':'-separatedlist ofkey=valuepairs. - A
':'-separatedlist ofvalue.
In this case, the keysare assumed to bethe option names in the orderthey are declared. E.g.
thefade filterdeclares three options in this order –type, start_frame and nb_frames.
Then the parameter listin:0:30means that:- the value
inis assigned to the optiontype, 0tostart_frame30tonb_frames.
- the value
A ':'-separated list of mixed direct value and long key=value pairs.
- The direct value
must precedethekey=valuepairs, - and follow the same constraints order of the previous point.
The following key=value pairs can be set in any preferred order.
If the option value itself is a list of items (e.g. the format filter takes a list of pixel formats),
the items in the list are usually separated by '|'.
The list of arguments can be quoted using the character "'" as initial and ending mark,
and the character '\' for escaping the characters within the quoted text;
otherwise the argument string is considered terminated when the next special character (belonging to the set '[]=;,' ) is encountered.
A special syntax implemented in the ffmpeg CLI tool allows loading option values from files.
This is done be prepending a slash '/' to the option name, then
the supplied value is interpreted as a path from which the actual value is loaded. E.g.
ffmpeg -i <INPUT> -vf drawtext=/text=/tmp/some_text <OUTPUT>
will load the text to be drawn from /tmp/some_text.
API users wishing to implement a similar feature should use the avfilter_graph_segment_*() functions together with custom IO code.
The name and arguments of the filter are optionally preceded and followed by a list of link labels.
A link label allows one to name a link and associate it to a filter output or input pad.
the preceding labels in_link_1 ... in_link_N, are associated to the filter input pads,
the following labels out_link_1 ... out_link_M, are associated to the filter output pads.
When two link labels with the same name are found in the filtergraph,
a link between the corresponding input and output pad is created.
If an output pad is not labelled, it is linked by default to the first unlabelled input pad of the next filter in the filterchain.
For example in the filterchain
nullsrc, split[L1], [L2]overlay, nullsink
the split filter instance has two output pads, and the overlay filter instance two input pads.
The first output pad of split is labelled "L1",
the first input pad of overlay is labelled "L2",
and the second output pad of split is linked to the second input pad of overlay, which are both unlabelled.
In a filter description,
if the input label of the first filter is not specified, "in" is assumed;
if the output label of the last filter is not specified, "out" is assumed.
In a complete filterchain, all the unlabelled filter input and output pads must be connected.
A filtergraph is considered valid if all the filter input and output pads of all the filterchains are connected.
Leading and trailing whitespaces (space, tabs, or line feeds) separating tokens in the filtergraph specification are ignored.
This means that the filtergraph can be expressed using empty lines and spaces to improve redability.
For example, the filtergraph:
testsrc,split[L1],hflip[L2];[L1][L2] hstack
can be represented as:
testsrc,
split [L1], hflip [L2];
[L1][L2] hstack
Libavfilter will automatically insert scale filters where format conversion is required.
It is possible to specify swscale flags for those automatically inserted scalers by prepending sws_flags=flags; to the filtergraph description.
Here is a BNF description of the filtergraph syntax:
NAME ::= sequence of alphanumeric characters and '_'
FILTER_NAME ::= NAME["@"NAME]
LINKLABEL ::= "[" NAME "]"
LINKLABELS ::= LINKLABEL [LINKLABELS]
FILTER_ARGUMENTS ::= sequence of chars (possibly quoted)
FILTER ::= [LINKLABELS] FILTER_NAME ["=" FILTER_ARGUMENTS] [LINKLABELS]
FILTERCHAIN ::= FILTER [,FILTERCHAIN]
FILTERGRAPH ::= [sws_flags=flags;] FILTERCHAIN [;FILTERGRAPH]
4.2 Notes on filtergraph escaping
Filtergraph description composition entails several levels of escaping. See (ffmpeg-utils)the "Quoting and escaping" section in the ffmpeg-utils(1) manual for more information about the employed escaping procedure.
A first level escaping affects the content of each filter option value, which may contain the special character : used to separate values, or one of the escaping characters '.
A second level escaping affects the whole filter description, which may contain the escaping characters ' or the special characters [],; used by the filtergraph description.
Finally, when you specify a filtergraph on a shell commandline, you need to perform a third level escaping for the shell special characters contained within it.
For example, consider the following string to be embedded in the drawtext filter description text value:
this is a 'string': may contain one, or more, special characters
This string contains the ' special escaping character, and the : special character, so it needs to be escaped in this way:
text=this is a 'string': may contain one, or more, special characters
A second level of escaping is required when embedding the filter description in a filtergraph description, in order to escape all the filtergraph special characters. Thus the example above becomes:
drawtext=text=this is a \'string\'\: may contain one, or more, special characters
(note that in addition to the ' escaping special characters, also , needs to be escaped).
Finally an additional level of escaping is needed when writing the filtergraph description in a shell command, which depends on the escaping rules of the adopted shell. For example, assuming that \ is special and needs to be escaped with another , the previous string will finally result in:
-vf "drawtext=text=this is a \\\'string\\\'\\: may contain one\, or more\, special characters"
In order to avoid cumbersome escaping when using a commandline tool accepting a filter specification as input, it is advisable to avoid direct inclusion of the filter or options specification in the shell.
For example, in case of the drawtext filter, you might prefer to use the textfile option in place of text to specify the text to render.
SciTech-AV-Video-DVP(Digital Video Processing)-CV/CG-ffmpeg-libavfilter:数字过滤器-的更多相关文章
- Digital Image Processing 学习笔记3
第三章 灰度变换与空间滤波 3.1 背景知识 3.1.1 灰度变换和空间滤波基础 本章节所讨论的图像处理技术都是在空间域进行的.可以表示为下式: $$g(x, y) = T[f(x,y)]$$ 其中$ ...
- 关于AXI4-Stream to Video Out 和 Video Timing Controller IP核学习
关于AXI4-Stream to Video Out 和 Video Timing Controller IP核学习 1.AXI4‐Stream to Video Out Top‐Level Sign ...
- Digital image processing(数字图像处理)
In computer science, digital image processing is the use of computer algorithms to perform image pro ...
- 信号处理的好书Digital Signal Processing - A Practical Guide for Engineers and Scientists
诚心给大家推荐一本讲信号处理的好书<Digital Signal Processing - A Practical Guide for Engineers and Scientists>[ ...
- (转) s-video vs. composite video vs. component video 几种视频格式详细说明和比较
之前对着几种视频格式认识不是很清晰,所以看数据手册的时候,看的也是稀里糊涂的. 因为项目中需要用到cvbs做视频输入,在元器件选型上,看到tw2867的数据手册上,有这么一句话: The TW2867 ...
- Digital Imaging Processing 数字图像处理
8-Bit and 16-Bit Images 关于量化压缩与量化补偿 RGB Bayer Color分析 彩色CCD/CMOS的格式和计算机中的读取格式
- Digital Image Processing 学习笔记2
第二章 2.1视觉感知要素 2.1.1 人眼的结构 眼睛由角膜与巩膜外壳.脉络膜和视网膜包围,晶状体由通信的纤维细胞层组成,并由附在睫状体上的纤维悬挂:视网膜上分布两类光感受器(锥状体和杆状体),他们 ...
- How do I convert an IIR filter into a FIR filter in digital signal processing?
Maybe you were asking if there is some kind of design tool allowing to convert an IIR filter into an ...
- Digital Image Processing 学习笔记1
第一章 1.1 数字图像 一幅图像可以定义为一个而为函数, 其中x和y是空间坐标,而在任何一对空间坐标(x, y)处的幅值f称为图像在该点处的强度或灰度.当x, y和灰度值f是有限的离散数值时,该图像 ...
- Digital Image Processing
20190919 Review CCD:高端天文学,敏感度高,速度慢,成本高: CMOS:普遍使用,嵌入手机,速度快,有模式噪声(Pattern Noise,现在可以解决): 空间分辨率和时间分辨率: ...
随机推荐
- strftime()函数的用法
strftime()函数的用法 strftime()函数可以把YYYY-MM-DD HH:MM:SS格式的日期字符串转换成其它形式的字符串.strftime()的语法是strftime(格式, 日期/ ...
- AI 辅助开发实战分享:解决Selenium自动化设置Ant时间组件难题
AI 辅助开发实战分享:解决Selenium自动化设置Ant时间组件难题 在软件开发这一块,自动化那可是提高效率.少出错的关键.不过呢,在实际搞自动化开发的时候,开发者们常常会碰到各种各样的麻烦和障碍 ...
- .NET AI从0开始入门 SemanticKernel 从基础到实践
引言 本教程将带你全面了解SemanticKernel,一款强大的AI开发工具包.以下内容基于实际代码示例,帮助你快速掌握使用技巧. 资源链接: 教程代码仓库:https://github.com/A ...
- Dify+DeepSeek实战教程!企业级 AI 文档库本地化部署,数据安全与智能检索我都要
上次折腾完 DeepSeek 的本地私有化部署后,心里就一直琢磨着:能不能给咱们 Rainbond 的用户再做点实用的东西?毕竟平时总收到反馈说文档查找不够方便,要是能有个 AI 文档助手该多好.正想 ...
- AD 侦查-SMB_2
本文通过 Google 翻译 AD Recon – NetBIOS (137/138/139) and SMB (445) Part-2 这篇文章所产生,本人仅是对机器翻译中部分表达别扭的字词进行了校 ...
- 第9.2讲、Tiny Decoder(带 Mask)详解与实战
自己搭建一个 Tiny Decoder(带 Mask),参考 Transformer Encoder 的结构,并添加 Masked Multi-Head Self-Attention,它是 Decod ...
- windows环境下的常用命令
1.appwiz.cpl 程序和功能 2.certmgr.msc 证书管理实用程序 3.control 控制面板 4.firewall.cpl 防火墙 5.fsmgmt.msc 共享文件夹管理器 6. ...
- openssl头文件出现DEPRECATEDIN_1_1_0导致引入头文件时程序无法编译
我使用的是unbuntu20.04版本中,通过apt安装的openssl,发现openssl中的多个库文件中会出现类似'DEPRECATEDIN_1_1_0(unsigned char *ASN1_S ...
- springboot的jar包转war放入tomcat
作者:故事我忘了¢个人微信公众号:程序猿的月光宝盒 目录 1. 修改pom文件,打包形式改为war 2.移除内嵌的tomcat模块,但是为了在本机测试方便,我们还需要引入它,所以配置如下 3.修改启动 ...
- AI生成的一篇官网代码,有兴趣可以参考一下
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...