0%

ffmpeg filter 滤镜/过滤器

语法

1
2
3
4
5
6
7
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]

-map用法见 map用法

在 Filter Name 前面的LinkLables是输入, 在Filter Name后面的LinkLables是输出
输入LinkLable可以通过[file_index:stream_specifier]来描述, 其中file_index是指定输入文件, 文件按命令行上出现的顺序从0开始编号;
一个文件中可能包含多个流, stream_specifier用来限定指定文件中的哪些流

输出LinkLable表示给处理后的流起一个别名

Stream specifiers

Stream specifiers可能有多种格式,分别如下

  • stream_index
    直接指定流下标,从0开始编号

  • stream_type[:additional_stream_specifier]
    stream_type取值:
    v: 所有视频流
    V: 没有附加图片/缩略图/封面的视频流
    a: 音频流
    s: subtitle 字幕
    d: 数据
    t: 附件
    stream_type 和 additional_stream_specifier 是逻辑与的关系

  • p:program_id[:additional_stream_specifier]
    Matches streams which are in the program with the id program_id. If additional_stream_specifier is used, then it matches streams which both are part of the program and match the additional_stream_specifier.

  • #stream_id or i:stream_id
    Match the stream by stream id (e.g. PID in MPEG-TS container).

  • m:key[:value]
    Matches streams with the metadata tag key having the specified value. If value is not given, matches streams that contain the given tag with any value.

  • u
    Matches streams with usable configuration, the codec must be defined and the essential information such as video dimension or audio sample rate must be present.

滤镜分类

音频滤镜

视频滤镜

多媒体滤镜

仅输入滤镜

仅输出滤镜

常用命令

将两个图像垂直合并

1
ffmpeg -i input0 -i input1 -filter_complex vstack=inputs=2 output

将两个图像水平合并

1
ffmpeg -i input0 -i input1 -filter_complex hstack=inputs=2 output

将两个图像水平合并并添加分隔栏

1
2
# iw 是输入宽度
ffmpeg -i input0 -i input1 -filter_complex "[0]pad=iw+5:color=black[left];[left][1]hstack=inputs=2" output

参考资料

JPG图片合并