如何简化ffmpeg的脚本?

时间:2018-03-27 11:08:24

标签: video ffmpeg simplify

我希望简化此脚本

我有这个简单的脚本;我想简化这个脚本,任何人都可以帮助我添加具有适当时间间隔和淡入淡出效果的文本。

ffmpeg -y -i video.mp4 -filter_complex \
"[0]split[base][text];[text] \
drawtext=fontfile=gvr.otf:text='Which of these is not an event listener adapter defined in the java.awt.event package?': fontcolor=white: fontsize=40: x=100:y=200, \
format=yuva444p,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=8:d=1:alpha=1[subtitles]; \
[base][subtitles]overlay" test_out.mp4

ffmpeg -y -i test_out.mp4 -filter_complex \
"[0]split[base][text];[text] \
drawtext=fontfile=gvr.otf:text='a) public void apple(String s, int i) {}': fontcolor=white: fontsize=40: x=100:y=(200) + 50 * 2, \
format=yuva444p,fade=t=in:st=3:d=1:alpha=1,fade=t=out:st=8:d=1:alpha=1[subtitles]; \
[base][subtitles]overlay" test_out1.mp4

ffmpeg -y -i test_out1.mp4 -filter_complex \
"[0]split[base][text];[text] \
drawtext=fontfile=gvr.otf:text='b) public int apple(int i, String s) {}': fontcolor=white: fontsize=40: x=100:y=(200) + 50 * 3, \
format=yuva444p,fade=t=in:st=4:d=1:alpha=1,fade=t=out:st=8:d=1:alpha=1[subtitles]; \
[base][subtitles]overlay" test_out2.mp4

ffmpeg -y -i test_out2.mp4 -filter_complex \
"[0]split[base][text];[text] \
drawtext=fontfile=gvr.otf:text='c) public void apple(int i, String mystring) {}': fontcolor=white: fontsize=40: x=100:y=(200) + 50 * 4, \
format=yuva444p,fade=t=in:st=5:d=1:alpha=1,fade=t=out:st=8:d=1:alpha=1[subtitles]; \
[base][subtitles]overlay" test_out3.mp4

ffmpeg -y -i test_out3.mp4 -filter_complex \
"[0]split[base][text];[text] \
drawtext=fontfile=gvr.otf:text='d) public void Apple(int i, String s) {}': fontcolor=white: fontsize=40: x=100:y=(200) + 50 * 5, \
format=yuva444p,fade=t=in:st=6:d=1:alpha=1,fade=t=out:st=8:d=1:alpha=1[subtitles]; \
[base][subtitles]overlay" test_out4.mp4

1 个答案:

答案 0 :(得分:1)

您可以在drawtext中使用alpha表达式

ffmpeg -y -i video.mp4 -vf "\
drawtext=fontfile=gvr.otf:text='Which of these is not an event listener adapter defined in the java.awt.event package?':fontcolor=white:fontsize=40:x=100:y=200:alpha='lte(t,2)*(t-1)+between(t,2,8)*1+gte(t,8)*(1-(t-8))', \
drawtext=fontfile=gvr.otf:text='a) public void apple(String s, int i) {}':fontcolor=white:fontsize=40:x=100:y=(200) + 50 * 2:alpha='lte(t,3)*(t-2)+between(t,3,8)*1+gte(t,8)*(1-(t-8))', \
drawtext=fontfile=gvr.otf:text='b) public int apple(int i, String s) {}':fontcolor=white:fontsize=40:x=100:y=(200) + 50 * 3:alpha='lte(t,4)*(t-3)+between(t,4,8)*1+gte(t,8)*(1-(t-8))', \
drawtext=fontfile=gvr.otf:text='c) public void apple(int i, String mystring) {}':fontcolor=white:fontsize=40:x=100:y=(200) + 50 * 4:alpha='lte(t,5)*(t-4)+between(t,5,8)*1+gte(t,8)*(1-(t-8))', \
drawtext=fontfile=gvr.otf:text='d) public void Apple(int i, String s) {}':fontcolor=white:fontsize=40:x=100:y=(200) + 50 * 5:alpha='lte(t,6)*(t-5)+between(t,6,8)*1+gte(t,8)*(1-(t-8))'" out.mp4

每个alpha表达式的格式为

alpha='lte(t,FADEIN-END-TIME)*(t-FADEIN-START-TIME)+between(t,OPAQUE-START-TIME,OPAQUE-END-TIME)*1+gte(t,FADEOUT-START-TIME)*(1-(t-FADEOUT-START-TIME))'