不会飞的章鱼

熟能生巧,勤能补拙;念念不忘,必有回响。

使用FFmpeg对视频增加转场特技功能

先来看网上存在的一个ffmpeg脚本

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
40
41
#!/bin/bash
# Example of concatenating 3 mp4s together with 1-second transitions between them.

tpath="/ffmpeg/transitions/"
x264="-look_ahead 0 -ac 2 -c:v h264_qsv -profile:v high -level 3.1 -preset:v veryfast"
ki="-keyint_min 72 -g 72 -sc_threshold 0"
br="-b:v 3000k -minrate 3000k -maxrate 6000k -bufsize 6000k -b:a 128k"

ffmpeg -hide_banner \
-i 1.mp4 \
-i 2.mp4 \
-i 3.mp4 \
-filter_complex " \
[0:a] atrim=0:5 [a0]; \
[1:a] atrim=0:5 [a1]; \
[2:a] atrim=0:6 [a2]; \
\
[0:v] split [v000] [v010]; \
[1:v] split [v100] [v110]; \
[2:v] split [v200] [v210]; \
\
[v000] trim=0:5 [v001]; \
[v010] trim=5:6 [v011t]; \
[v011t] setpts=PTS-STARTPTS [v011]; \
\
[v100] trim=0:5 [v101]; \
[v110] trim=5:6 [v111t]; \
[v111t] setpts=PTS-STARTPTS [v111]; \
\
[v200] trim=0:5 [v201]; \
[v210] trim=5:6 [v211t]; \
[v211t] setpts=PTS-STARTPTS [v211]; \
\
[v011] [v101] gltransition=duration=1:source=${tpath}WaterDrop.glsl [vt0]; \
[v111] [v201] gltransition=duration=1:source=${tpath}crosswarp.glsl [vt1]; \
\
[v001] [vt0] [vt1] [v211] concat=n=4 [outv]; \
[a0] [a1] [a2] concat=n=3:v=0:a=1 [outa]" \
-map [outv] -map [outa] \
${x264} ${ki} ${br} \
-y ffmpeg-gl-transition-concat.mp4

流程简介

github上的脚本如下

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
#!/bin/bash
# Example of concatenating 3 mp4s together with 1-second transitions between them.

./ffmpeg \
-i media/0.mp4 \
-i media/1.mp4 \
-i media/2.mp4 \
-filter_complex " \
[0:v]split[v000][v010]; \
[1:v]split[v100][v110]; \
[2:v]split[v200][v210]; \
[v000]trim=0:3[v001]; \
[v010]trim=3:4[v011t]; \
[v011t]setpts=PTS-STARTPTS[v011]; \
[v100]trim=0:3[v101]; \
[v110]trim=3:4[v111t]; \
[v111t]setpts=PTS-STARTPTS[v111]; \
[v200]trim=0:3[v201]; \
[v210]trim=3:4[v211t]; \
[v211t]setpts=PTS-STARTPTS[v211]; \
[v011][v101]gltransition=duration=1:source=./crosswarp.glsl[vt0]; \
[v111][v201]gltransition=duration=1[vt1]; \
[v001][vt0][vt1][v211]concat=n=4[outv]" \
-map "[outv]" \
-c:v libx264 -profile:v baseline -preset slow -movflags faststart -pix_fmt yuv420p \
-y out.mp4

相关过滤器功能

  • split,过滤器创建两个输入文件的拷贝并标记为[a],[b];
  • trim,修剪视频;
  • setpts=PTS-STARTPTS。重编码,算pts;

图示

链接

Windows如何实现视频过渡滑入视频特效?

ffmpeg 视频过度滤镜 gltransition

------ 本文结束------
如果本篇文章对你有帮助,可以给作者加个鸡腿~(*^__^*),感谢鼓励与支持!