转自:https://www.jianshu.com/p/3fa0b04027ce
ffmpeg中的filter
FFmpeg中的libavfilter提供了一整套的基于filter的机制。filter本身是一个插件的形式,可以快速的组装需要的效果。
比如下面的filter,可以实现视频的水平镜像效果。
1 | ffplay.exe sample.rmvb -vf hflip |
FFmpeg中filter分为:
source filter (只有输出)
audio filter
video filter
Multimedia filter
sink filter (只有输入)
除了source和sink filter,其他filter都至少有一个输入、至少一个输出。
介绍了这么多,下面也是一个例子,使用filter实现宽高减半显示:
1 | ffplay.exe sample.rmvb -vf scale=iw/2:ih/2 |
可以用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | [TheFlyingPenguindeMacBook-Pro:gzl Private$ ffmpeg -filters ffmpeg version 3.1 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 7.0.2 (clang-700.1.81) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-librtmp --enable-libfaac --enable-ffplay --disable-lzma --enable-nonfree --enable-vda libavutil 55. 27.100 / 55. 27.100 libavcodec 57. 48.101 / 57. 48.101 libavformat 57. 40.101 / 57. 40.101 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 46.102 / 6. 46.102 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100 libpostproc 54. 0.100 / 54. 0.100 Filters: T.. = Timeline support .S. = Slice threading ..C = Command support A = Audio input/output V = Video input/output N = Dynamic number and/or type of input/output | = Source or sink filter ... abench A->A Benchmark part of a filtergraph. ... ... aresample A->A Resample audio data. ... ... copy V->V Copy the input video unchanged to the output. ... T.. delogo V->V Remove logo from input video. ... ... format V->V Convert the input video to one of the specified pixel formats. ... fps V->V Force constant framerate. ... ... reverse V->V Reverse a clip. TSC rotate V->V Rotate the input image. T.. sab V->V Apply shape adaptive blur. ..C scale V->V Scale the input video size and/or convert the image format. ... ... split V->N Pass on the input to N video outputs. ... |
scale
将输入的1920x1080缩小到960x540输出:
1 | ./ffmpeg -i input.mp4 -vf scale=960:540 output.mp4 |
//ps: 如果540不写,写成-1,即scale=960:-1, 那也是可以的,ffmpeg会通知缩放滤镜在输出时保持原始的宽高比。
crop
Crop the input video to given dimensions.
It accepts the following parameters:
- w, out_w
The width of the output video. It defaults to iw.
This expression is evaluated only once during the filter configuration, or when the ‘w’ or ‘out_w’ command is sent.- h, out_h
The height of the output video. It defaults to ih.
This expression is evaluated only once during the filter configuration, or when the ‘h’ or ‘out_h’ command is sent.- x
The horizontal position, in the input video, of the left edge of the output video.
It defaults to (in_w-out_w)/2.
This expression is evaluated per-frame.- y
The vertical position, in the input video, of the top edge of the output video.
It defaults to (in_h-out_h)/2.
This expression is evaluated per-frame.
- Crop area with size 100x100 at position (12,34).
1 | crop=100:100:12:34 |
- Using named options, the example above becomes:
1 | crop=w=100:h=100:x=12:y=34 |
References:
https://www.cnblogs.com/tocy/p/ffmpeg-filter-intro.html
http://www.ffmpeg.org/ffmpeg-filters.html#crop
https://blog.csdn.net/newchenxf/article/details/51364105
作者:FlyingPenguin
链接:https://www.jianshu.com/p/3fa0b04027ce
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。