[FFmpeg Practical Combat] How to use filter and some functional commands

Original address: https://www.cnblogs.com/gccbuaa/p/6800446.html

1. Add subtitles

​ 命令:ffmpeg -i -filter_complex subtitles=filename=-y

​ Description: Use libass to embed subtitles for videos. Subtitles are hard subtitles directly embedded into the video.

​ Reference: http://ffmpeg.org/ffmpeg-filters.html#subtitles-1

2. Cut

​ 命令:ffmpeg -i -ss 0 -t 10 -y

​ Note: ss follows the starting time, and t is the duration. The above command means to intercept 10 seconds starting from 0 seconds.

​ Reference: http://ffmpeg.org/ffmpeg.html

3. Zoom

​ Instruction: ffmpeg -i -filter_complex scale=320:240 -y

​ Description: The scale parameter is width and height.

4. Cutting

​ Instruction: ffmpeg -i -filter_complex crop=320:240:0:0 -y

​ Note: crop=320:240:0:0 is the cropping parameter. The detailed meaning is crop=width:height❌y, where width and height represent the size after cropping, and x:y represents the coordinates of the upper left corner of the cropping area.

5. Add watermark

命令:ffmpeg -i src.avi -vf “movie=[logo];[in][logo]overlay=100:100[out]”-y

​ Note: LogoName is the name of the picture, overlay=100:100 means overlay=x:y, and the watermark starts to be added at the (x, y) coordinates.

​ Upper left corner: overlay=10:10

​ Upper right corner: overlay=main_w-overlay_w-10:10

​ Bottom left corner: overlay=10:main_h-overlay_h-10

​ Bottom right corner: overlay=main_w-overlay_w-10:main_h-overlay_h-10

6. Splicing videos

​The first command:

Step 1: ffmpeg -i INPUT -fmpeg OUTPUT

Step 2: copy /b INPUT+INPUT OUTPUT

Step 3: ffmpeg -i INPUT -f FORMAT OUTPUT

​ Description: The first step is to convert the input files into the same format, the second step is to use the copy command to merge the files, and the third step is to convert the merged files into the final video.

​Example: Merge two videos named test.avi and test1_2.mp4 into resu.avi.

​The first step: ffmpeg -itest1.avi test1.mpg

​ ffmpeg-i test1_2.mp4 test2.mpg

Step 2: copy /btest1.mpg+test2.mpg resu.mpge

​ Third step: ffmpeg -iresu.mpge -y resu.avi

Another command:

ffmpeg -i 1.mov -i 2.wmv -filter_complex “[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]” -map [v] -map [a] output.mp4

7. Rotate

命令: ffmpeg -i -filter_complex transpose=X -y

Note: transpose=1 rotates 90° clockwise, transpose=2 rotates 90° counterclockwise.

8. Mirror

Mirror up and down

Order:

ffmpeg -i src.avi -vf “split[mian][tmp];[tmp]crop=iw:ih/2:0:0,vflip[flip];[mian][flip]overlay=0:H/2”-y GHO.avi

Note: It can be seen from the command that crop and vflip are on the same pipeline. Their processing flow is as shown in the following figure:

Insert image description here

You can use this filter to flip upside down. The command is as follows: ffmpeg-i src.avi -vf “split [main][tmp]; [tmp] crop=iw:ih:0:0, vflip [flip];[main ][flip] overlay=0:0” The processing effect of GHO2.avi is the same as the command ffmpeg -isrc.avi -vf vflip GHO_v_1.avi. This is written just to better understand the filter processing chain.

Mirror left and right

命令: ffmpeg -i src.avi-vf “split [main][tmp]; [tmp] crop=iw/2:ih:0:0, hflip [flip]; [main][flip]overlay=W/2:0” GHO_H.avi

Note: The process is the same as the upper and lower mirroring, except that the coordinates are changed. And specify a filter named hfilp.

You can use this filter to reverse left and right. The command is as follows: ffmpeg-i src.avi -vf “split [main][tmp]; [tmp] crop=iw:ih:0:0, hflip [flip];[main ][flip] overlay=W:0” GHO_H_1.avi has the same effect as the command ffmpeg -i src.avi-vf hflip GHO_H_1.avi. This is written just to better understand the filter processing chain.

Summary: The split filter splits the input into 2 outputs . The crop filter selects the image range for flipping, the vflip and hflip filters flip the crop-cut image (vertically, horizontally), and the overlay filter specifies coordinates to paste the flipped image.

9. Add black borders

命令: ffmpeg -isrc.avi -vf pad=1280:800:0:40:black -y test_pad.avi

Description: pad=width:high❌y:coler. The width and height here refer to the resulting video size (including the size with black borders). XY refers to the source video added to the position of the result video, and coler is the fill color.

10. Adjust the volume

​Command: ffmpeg -i -vol X

​ Description: No explanation

  >>> 音视频开发 视频教程: https://ke.qq.com/course/3202131?flowToken=1031864 
  >>> 音视频开发学习资料、教学视频,免费分享有需要的可以自行添加学习交流群 739729163 领取

Guess you like

Origin blog.csdn.net/weixin_52622200/article/details/131538202