完整编辑视频步骤(开始)
- 生成片头片尾的视频 -t 代表多少秒
ffmpeg -y -loop 1 -i head.jpg -t 5 -c:v libx264 head.flv
ffmpeg -y -loop 1 -i tail.jpg -t 27 -c:v libx264 tail.flv
- 根据字幕文件生成对应的视频文件
ffmpeg -y -i head.flv -vf ass=head.ass -b:v 3000K case_head.flv
ffmpeg -y -i ../case.mp4 -vf ass=main_v2.ass -b:v 3000K case_main.flv
ffmpeg -y -i tail.flv -vf ass=tail.ass -b:v 3000K case_tail.flv
- 转换视频文件flv 为mpg
ffmpeg -y -i case_tail.flv -qscale:v 1 tail1.mpg
ffmpeg -y -i case_head.flv -qscale:v 1 head1.mpg
ffmpeg -y -i case_main.mp4 -qscale:v 1 main1.mpg
- 合并文件,并将要合并的文件写入文件list.txt
内容如下
file head1.mpg
file main1.mpg
file tail1.mpg
ffmpeg -y -f concat -i list.txt -vcodec copy concat.mpg
ffmpeg -y -i concat.mpg -qscale:v 1 concat.mp4
-
至此,片头 内容和片尾 合成了一个mp4视频,但是此时还没有声音
-
给内容视频增加趣味贴纸
ffmpeg -y -i concat.mp4 -ignore_loop 0 -itsoffset 14 -i ../gif0408/妥妥的.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:200[wm];[a][wm]overlay=y='if(gte(t,14), if(gte(t,17), NAN,750-min((t-14),1)*600 ),NAN ):x=750:shortest=1'[v2]" -map [v2] -c:v libx264 move_up.mp4
ffmpeg -y -i move_up.mp4 -ignore_loop 0 -itsoffset 19 -i ../87.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:380[wm];[a][wm]overlay=x='if(gte(t,19), if(gte(t,21), NAN,850-min((t-19),1)*120 ),NAN ):y=150:shortest=1'[v2]" -map [v2] -c:v libx264 move_left.mp4
ffmpeg -y -i move_left.mp4 -ignore_loop 0 -itsoffset 26 -i ../gif0408/棒.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:200[wm];[a][wm]overlay=y='if(gte(t,26), if(gte(t,29), NAN,30+min((t-26),1)*120 ),NAN ):x=750:shortest=1'[v2]" -map [v2] -c:v libx264 move_down.mp4
- 素材问题,没有合适的素材,自己找,gif时间短,不能匹配,有颤抖,移动,没有闪一下的问题
ffmpeg -y -i move_down.mp4 -ignore_loop 0 -itsoffset 43 -i ../87.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:380[wm];[a][wm]overlay=x='if(gte(t,43), if(gte(t,46), NAN,750+mod(floor(n/3),2)10 ),NAN ):y=50+mod(floor(n/3),2)10:shortest=1'[v2]" -map [v2] -c:v libx264 chandou_gif.mp4
ffmpeg -y -ignore_loop 0 -itsoffset 50 -i ../gif0408/可以.gif -i chandou_gif.mp4 -filter_complex "[0]format=pix_fmts=rgba[v0];[v0]scale=-1:200[v5];[v5]rotate='sin(PI/mod(floor(n/3),2))':ow='max(iw,ih)':oh=ow:c=none[v1];[1][v1]overlay=x='if(gte(t,50), if(gte(t,53), NAN,750),NAN ):y=20:shortest=1'[v2]" -map [v2] -c:v libx264 yaobai_gif.mp4
ffmpeg -y -i yaobai_gif.mp4 -ignore_loop 0 -itsoffset 60 -i ../mov04/18/gif.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:720[wm];[a][wm]overlay=x='if(gte(t,60), if(gte(t,62), NAN,300),NAN ):y=50-300sin((t-60)3/2):shortest=1'[v2]" -map [v2] -c:v libx264 tiaodong_gif.mp4
ffmpeg -y -i tiaodong_gif.mp4 -ignore_loop 0 -itsoffset 74 -i ../mov04/19/gif.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:720[wm1];[wm1]pad=1300:740:0:0:0x00F8FF@0[v1];[v1]rotate=50-0.4sin(8PI/5t):ow='max(iw,ih)':oh=ow:c=none[wm];[a][wm]overlay=x='if(gte(t,74), if(gte(t,75.5), NAN,400),NAN ):y=-500+20sin((t-74)*1/2):shortest=1'[v2]" -map [v2] -c:v libx264 yushua_gif.mp4
ffmpeg -y -i yushua_gif.mp4 -ignore_loop 0 -itsoffset 79 -i ../87.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:'300+25min(t-79,1)':eval=frame[wm];[a][wm]overlay=x='if(gte(t,79), if(gte(t,82), NAN,750-(50min(t-79,1))/3 ),NAN ):y=100-(50*min(t-79,1))/3:shortest=1'[v2]" -map [v2] -c:v libx264 danru_gif.mp4
ffmpeg -y -i danru_gif.mp4 -ignore_loop 0 -itsoffset 85 -i ../720/推荐.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:'
if(lte(1000(t-85),500),70+0.41000(t-85),
if(lte(1000(t-85.5),500),270-0.31000(t-85.5),
if(lte(1000(t-86),500),120+0.11000(t-86),
if(lte(1000(t-86.5),300),170-0.051000(t-86.5),
145))))':eval=frame[wm];
[a][wm]overlay=x='if(gte(t,85), if(gte(t,87), NAN,
if(lte(1000(t-85),500),850-(0.41000(t-85))/2,
if(lte(1000(t-85.5),500),750+(0.31000(t-85.5))/2,
if(lte(1000(t-86),500),825-(0.11000(t-86))/2,
if(lte(1000(t-86.5),300),800+(0.051000(t-86.5))/2,812.5)))) ),NAN )
:y=if(lte(1000(t-85),500),200-(0.41000(t-85))/2,
if(lte(1000(t-85.5),500),100+(0.31000(t-85.5))/2,
if(lte(1000(t-86),500),175-(0.11000(t-86))/2,
if(lte(1000(t-86.5),300),150+(0.051000(t-86.5))/2,162.5)))):shortest=1'[v2]" -map [v2] -c:v libx264 tanhuang_gif.mp4
ffmpeg -y -ignore_loop 0 -itsoffset 95 -i ../gif0408/撑腰.gif -i tanhuang_gif.mp4 -filter_complex "[0]format=pix_fmts=rgba[v0];[v0]scale=-1:300[v5];[v5]rotate='sin(PI(10(t-95)))*0.15':ow='max(iw,ih)':oh=ow:c=none[v1];[1][v1]overlay=x='if(gte(t,95), if(gte(t,97), NAN,750),NAN ):y=50:shortest=1'[v2]" -map [v2] -c:v libx264 xiaotiao_gif.mp4
-
根据视频长度生成静音音频文件 -t 后面是秒数
ffmpeg -y -f lavfi -t 127 -i anullsrc test.aac -y -
片头,片尾第三方生成,我们自己生成内容视频的音频文件
ffmpeg -y -i ../case.mp4 -vn -acodec copy case.aac -
此时,片头,内容,片尾音频都有了,开始转换格式为wav
ffmpeg -y -i test.aac test.wav
ffmpeg -y -i head.mp3 -acodec pcm_s16le -ac 1 -ar 8000 head.wav
ffmpeg -y -i case.aac main.wav
ffmpeg -y -i end.mp3 -acodec pcm_s16le -ac 1 -ar 8000 end.wav
- 如果片头片尾声音小了要扩大音量,这里片头片尾各扩大10分贝
ffmpeg -y -i head.wav -af "volume=10dB" head1.wav
ffmpeg -y -i end.wav -af "volume=10dB" end1.wav
-
开始合并音频文件
ffmpeg -y -i test.wav
-i head1.wav
-i main.wav
-i end1.wav
-filter_complex "[0]volume='1'[w0];
[1]adelay=1000|1000,volume='1'[w1];
[2]adelay=5000|5000,volume='1'[w2];
[3]adelay=100000|100000,volume='1'[w3];
[w0][w1][w2][w3]amix=inputs=4:duration=first:dropout_transition=0" -f mp3 00t1.mp3 -
合入其他特效音频文件
ffmpeg -y -i 00t1.mp3
-i ../mov04/2/wav.wav
-i ../mov04/4/wav.wav
-i ../mov04/8/wav.wav
-i ../mov04/9/wav.wav
-i ../mov04/12/wav.wav
-i ../mov04/14/wav.wav
-i ../mov04/17/wav.wav
-i ../mov04/18/wav.wav
-i ../mov04/19/wav.wav
-filter_complex "[0]volume='10.5'[w0];
[1]adelay=14000|14000,volume='1'[w1];
[2]adelay=19000|19000,volume='1'[w2];
[3]adelay=26000|26000,volume='1'[w3];
[4]adelay=43000|43000,volume='1'[w4];
[5]adelay=50000|50000,volume='1'[w5];
[6]adelay=60000|60000,volume='1'[w6];
[7]adelay=74000|74000,volume='1'[w7];
[8]adelay=79000|79000,volume='1'[w8];
[9]adelay=85000|85000,volume='1'[w9];
[w0][w1][w2][w3][w4][w5][w6][w7][w8][w9]amix=inputs=10:duration=first:dropout_transition=120" -f mp3 demo_main.mp3
- 将音频融入到视频里面去
ffmpeg -y -i tanhuang_gif.mp4 -i demo_main.mp3 -c:v copy -map 0:v:0 -map 1:a:0 demo_end.mp4
完整编辑视频步骤(结束)
完整编辑视频步骤版本2(开始)
-
生成片头片尾的视频 -t 代表多少秒
ffmpeg -y -loop 1 -i head.jpg -t 5 -c:v libx264 head.flv -
根据字幕文件生成对应的视频文件
ffmpeg -y -i head.flv -vf ass=head.ass -b:v 3000K case_head.flv
ffmpeg -y -i ../case.mp4 -vf ass=main.ass -b:v 3000K case_main.flv
- 转换视频文件flv 为mpg
ffmpeg -y -i case_head.flv -qscale:v 1 head1.mpg
ffmpeg -y -i case_main.flv -qscale:v 1 main1.mpg
- 合并文件,并将要合并的文件写入文件list.txt
内容如下
file head1.mpg
file main1.mpg
ffmpeg -y -f concat -i list.txt -vcodec copy concat.mpg
ffmpeg -y -i concat.mpg -qscale:v 1 concat.mp4
-
至此,片头 内容和片尾 合成了一个mp4视频,但是此时还没有声音
-
给内容视频增加趣味贴纸
ffmpeg -y -i concat.mp4 -ignore_loop 0 -itsoffset 14 -i ../gif0408/妥妥的.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:200[wm];[a][wm]overlay=y='if(gte(t,14), if(gte(t,17), NAN,750-min((t-14),1)*600 ),NAN ):x=750:shortest=1'[v2]" -map [v2] -c:v libx264 move_up.mp4
ffmpeg -y -i move_up.mp4 -ignore_loop 0 -itsoffset 19 -i ../87.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:380[wm];[a][wm]overlay=x='if(gte(t,19), if(gte(t,21), NAN,850-min((t-19),1)*120 ),NAN ):y=150:shortest=1'[v2]" -map [v2] -c:v libx264 move_left.mp4
ffmpeg -y -i move_left.mp4 -ignore_loop 0 -itsoffset 26 -i ../gif0408/棒.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:200[wm];[a][wm]overlay=y='if(gte(t,26), if(gte(t,29), NAN,30+min((t-26),1)*120 ),NAN ):x=750:shortest=1'[v2]" -map [v2] -c:v libx264 move_down.mp4
- 素材问题,没有合适的素材,自己找,gif时间短,不能匹配,有颤抖,移动,没有闪一下的问题
ffmpeg -y -i move_down.mp4 -ignore_loop 0 -itsoffset 43 -i ../87.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:380[wm];[a][wm]overlay=x='if(gte(t,43), if(gte(t,46), NAN,750+mod(floor(n/3),2)10 ),NAN ):y=50+mod(floor(n/3),2)10:shortest=1'[v2]" -map [v2] -c:v libx264 chandou_gif.mp4
ffmpeg -y -ignore_loop 0 -itsoffset 50 -i ../gif0408/可以.gif -i chandou_gif.mp4 -filter_complex "[0]format=pix_fmts=rgba[v0];[v0]scale=-1:200[v5];[v5]rotate='sin(PI/mod(floor(n/3),2))':ow='max(iw,ih)':oh=ow:c=none[v1];[1][v1]overlay=x='if(gte(t,50), if(gte(t,53), NAN,750),NAN ):y=20:shortest=1'[v2]" -map [v2] -c:v libx264 yaobai_gif.mp4
ffmpeg -y -i yaobai_gif.mp4 -ignore_loop 0 -itsoffset 60 -i ../mov04/18/gif.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:720[wm];[a][wm]overlay=x='if(gte(t,60), if(gte(t,62), NAN,300),NAN ):y=50-300sin((t-60)3/2):shortest=1'[v2]" -map [v2] -c:v libx264 tiaodong_gif.mp4
ffmpeg -y -i tiaodong_gif.mp4 -ignore_loop 0 -itsoffset 74 -i ../mov04/19/gif.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:720[wm1];[wm1]pad=1300:740:0:0:0x00F8FF@0[v1];[v1]rotate=50-0.4sin(8PI/5t):ow='max(iw,ih)':oh=ow:c=none[wm];[a][wm]overlay=x='if(gte(t,74), if(gte(t,75.5), NAN,400),NAN ):y=-500+20sin((t-74)*1/2):shortest=1'[v2]" -map [v2] -c:v libx264 yushua_gif.mp4
ffmpeg -y -ignore_loop 0 -itsoffset 95 -i ../gif0408/撑腰.gif -i yushua_gif.mp4 -filter_complex "[0]format=pix_fmts=rgba[v0];[v0]scale=-1:300[v5];[v5]rotate='sin(PI(2(t-95)))*0.15':ow='max(iw,ih)':oh=ow:c=none[v1];[1][v1]overlay=x='if(gte(t,95), if(gte(t,97), NAN,750),NAN ):y=50:shortest=1'[v2]" -map [v2] -c:v libx264 xiaotiao_gif.mp4
ffmpeg -y -i xiaotiao_gif.mp4 -ignore_loop 0 -itsoffset 79 -i ../87.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:'300+25min(t-79,1)':eval=frame[wm];[a][wm]overlay=x='if(gte(t,79), if(gte(t,82), NAN,750-(50min(t-79,1))/3 ),NAN ):y=100-(50*min(t-79,1))/3:shortest=1'[v2]" -map [v2] -c:v libx264 danru_gif.mp4
ffmpeg -y -i danru_gif.mp4 -ignore_loop 0 -itsoffset 85 -i ../720/推荐.gif -filter_complex "[0:0]scale=iw:ih[a];[1:0]scale=-1:'
if(lte(1000(t-85),500),70+0.41000(t-85),
if(lte(1000(t-85.5),500),270-0.31000(t-85.5),
if(lte(1000(t-86),500),120+0.11000(t-86),
if(lte(1000(t-86.5),300),170-0.051000(t-86.5),
145))))':eval=frame[wm];
[a][wm]overlay=x='if(gte(t,85), if(gte(t,87), NAN,
if(lte(1000(t-85),500),850-(0.41000(t-85))/2,
if(lte(1000(t-85.5),500),750+(0.31000(t-85.5))/2,
if(lte(1000(t-86),500),825-(0.11000(t-86))/2,
if(lte(1000(t-86.5),300),800+(0.051000(t-86.5))/2,812.5)))) ),NAN )
:y=if(lte(1000(t-85),500),200-(0.41000(t-85))/2,
if(lte(1000(t-85.5),500),100+(0.31000(t-85.5))/2,
if(lte(1000(t-86),500),175-(0.11000(t-86))/2,
if(lte(1000(t-86.5),300),150+(0.051000(t-86.5))/2,162.5)))):shortest=1'[v2]" -map [v2] -c:v libx264 tanhuang_gif.mp4
-
根据视频长度生成静音音频文件 -t 后面是秒数
ffmpeg -y -f lavfi -t 100 -i anullsrc test.aac -y -
片头,片尾第三方生成,我们自己生成内容视频的音频文件
ffmpeg -y -i ../case.mp4 -vn -acodec copy case.aac -
此时,片头,内容,片尾音频都有了,开始转换格式为wav
ffmpeg -y -i test.aac test.wav
ffmpeg -y -i head.mp3 -acodec pcm_s16le -ac 1 -ar 8000 head.wav
ffmpeg -y -i case.aac main.wav
ffmpeg -y -i end.mp3 -acodec pcm_s16le -ac 1 -ar 8000 end.wav
- 如果片头片尾声音小了要扩大音量,这里片头片尾各扩大10分贝
ffmpeg -y -i head.wav -af "volume=10dB" head1.wav
- 开始合并音频文件
ffmpeg -y -i test.wav
-i head1.wav
-i main.wav
-filter_complex "[0]volume='1'[w0];
[1]adelay=1000|1000,volume='1'[w1];
[2]adelay=5000|5000,volume='1'[w2];
[w0][w1][w2]amix=inputs=3:duration=first:dropout_transition=0" -f mp3 00t1.mp3
- 合入其他特效音频文件
ffmpeg -y -i 00t1.mp3
-i ../mov04/2/wav.wav
-i ../mov04/4/wav.wav
-i ../mov04/8/wav.wav
-i ../mov04/9/wav.wav
-i ../mov04/12/wav.wav
-i ../mov04/14/wav.wav
-i ../mov04/17/wav.wav
-i ../mov04/18/wav.wav
-i ../mov04/19/wav.wav
-i ../mov04/2/wav.wav
-filter_complex "[0]volume='10.5'[w0];
[1]adelay=14000|14000,volume='1'[w1];
[2]adelay=19000|19000,volume='1'[w2];
[3]adelay=26000|26000,volume='1'[w3];
[4]adelay=43000|43000,volume='1'[w4];
[5]adelay=50000|50000,volume='1'[w5];
[6]adelay=60000|60000,volume='1'[w6];
[7]adelay=74000|74000,volume='1'[w7];
[8]adelay=79000|79000,volume='1'[w8];
[9]adelay=85000|85000,volume='1'[w9];
[10]adelay=95000|95000,volume='1'[w10];
[w0][w1][w2][w3][w4][w5][w6][w7][w8][w9][w10]amix=inputs=11:duration=first:dropout_transition=120" -f mp3 demo_main.mp3
- 将音频融入到视频里面去
ffmpeg -y -i tanhuang_gif.mp4 -i demo_main.mp3 -c:v copy -map 0:v:0 -map 1:a:0 demo_end.mp4
- 加入特效视频说明
ffmpeg -y -i demo_end.mp4 -vf ass=tx.ass -b:v 3000K tanhuang_gif2.mp4
网友评论