官方文档地址:http://www.ffmpeg.org/ffmpeg-all.html#toc-hflip
常用编译包:https://johnvansickle.com/ffmpeg/
拉取包
wget https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-4.4.1-i686-static.tar.xz

多段视频拼接成一个视频输出:

  1. ffmpeg -hide_banner
  2. -i a.mp4
  3. -i b.mp4
  4. -stream_loop -1 -i c.mp3
  5. -filter_complex
  6. "[0:v]scale=trunc(min(iw*1593/ih\,896)/2)*2:trunc(min(1593\,ih*896/iw)/2)*2,setsar=1/1[scale1];[scale1]pad=trunc(896/2)*2:trunc(1593/2)*2:trunc((896-iw)/2)*2/2:trunc((1593-ih)/2)*2/2:black[p0];[1:v]scale=trunc(min(iw*1593/ih\,896)/2)*2:trunc(min(1593\,ih*896/iw)/2)*2,setsar=1/1[scale2];[scale2]pad=trunc(896/2)*2:trunc(1593/2)*2:trunc((896-iw)/2)*2/2:trunc((1593-ih)/2)*2/2:black[p1];
  7. [0:a][1:a]concat=n=2:v=0:a=1[outa];
  8. [2:a]afade=t=in:st=0:d=1[a];
  9. [a]afade=t=out:st=24.28:d=1[a1];
  10. [a1]volume=0.3[a2];
  11. [a2][outa]amix=inputs=2:duration=longest[finala];
  12. [p0][p1]concat=n=2:v=1:a=0[outv]"
  13. -map "[outv]"
  14. -map "[finala]"
  15. -c:v libx264
  16. -preset superfast
  17. -nal-hrd cbr
  18. -b:v 5523560
  19. -minrate:v 5523560
  20. -maxrate:v 5523560
  21. -bufsize 11046720
  22. -r 25
  23. -minrate:a
  24. 130317
  25. -t 25.28
  26. -pix_fmt yuv420p
  27. -y result.mp4

视频图片图层叠加:

ffmpeg -hide_banner
-t 25.0
-i a.png
-i b.mp4
-i c.png
-filter_complex
"[0:v][1:v]overlay=x=92:y=164[out1];
[out1][2:v]overlay=x=0:y=0[out2]"
-map "[out2]"
-map "1:a"
-c:v libx264
-x264-params "nal-hrd=cbr"
-b:v 4M
-minrate 4M
-maxrate 4M
-bufsize 4M
-r 25
-y result.mp4

视频添加logo水印警示语:

ffmpeg -hide_banner
-i a.mp4
-i logo.png
-ignore_loop 0  -i watermark.gif
-stream_loop -1  -i b.mp3
-filter_complex "[0:v]scale=trunc(min(iw*1920/ih\,1080)/2)*2:trunc(min(1920\,ih*1080/iw)/2)*2,setsar=1/1[scale1];
[scale1]pad=trunc(1080/2)*2:trunc(1920/2)*2:trunc((1080-iw)/2)*2/2:trunc((1920-ih)/2)*2/2:black[p0];
[0:a]concat=n=1:v=0:a=1[outa];
[3:a]volume=0.3[a2];
[a2][outa]amix=inputs=2:duration=longest[finala];
[p0]concat=n=1:v=1:a=0[outv];
[outv][1]overlay=x=main_w-overlay_w-20:y=main_h-overlay_h-20[subttv];[2]scale=w=iw*oh/ih:min(ih\,180)[slogov1];
[slogov1]lut=a=val*0.4[alphav];
[subttv][alphav]overlay=x='if(lte(ld(1),W-w)*gt(ld(1),0),st(1,ld(1)+1.00*ld(2)),if(eq(ld(2),0),st(2,1),st(2,(-1*ld(2))));if(eq(ld(2),1)+eq(ld(2),0),st(1,1),st(1,(W-w-1))))':y='if(lte(ld(3),H-h)*gt(ld(3),0),st(3,ld(3)+2.00*ld(4)),if(eq(ld(4),0),st(4,1),st(4,(-1*ld(4))));
if(eq(ld(4),1)+eq(ld(4),0),st(3,1),st(3,(H-h-1))))'[ovlv]"
-map "[ovlv]"
-map "[finala]"
-c:v libx264
-preset superfast
-nal-hrd cbr
-b:v 4001705
-minrate:v 4001705
-maxrate:v  4001705
-bufsize  8003010
-r 25
-minrate:a 130310
-t 25.28
-pix_fmt yuv420p
-y result.mp4

多段视频拼接并添加logo水印音乐等:

ffmpeg -hide_banner
-i 1.mp4
-i 2.mp4
-i 3.mp4
-i 4.mp4
-i warningText.png
-i logo.png
-ignore_loop 0  -i watermark.gif
-stream_loop -1  -i musice.mp3
-filter_complex "[0:v]scale=trunc(min(iw*1920/ih\,1080)/2)*2:trunc(min(1920\,ih*1080/iw)/2)*2,setsar=1/1[scale1];
[scale1]pad=trunc(1080/2)*2:trunc(1920/2)*2:trunc((1080-iw)/2)*2/2:trunc((1920-ih)/2)*2/2:black[p0];[1:v]scale=trunc(min(iw*1920/ih\,1080)/2)*2:trunc(min(1920\,ih*1080/iw)/2)*2,setsar=1/1[scale2];
[scale2]pad=trunc(1080/2)*2:trunc(1920/2)*2:trunc((1080-iw)/2)*2/2:trunc((1920-ih)/2)*2/2:black[p1];[2:v]scale=trunc(min(iw*1920/ih\,1080)/2)*2:trunc(min(1920\,ih*1080/iw)/2)*2,setsar=1/1[scale3];
[scale3]pad=trunc(1080/2)*2:trunc(1920/2)*2:trunc((1080-iw)/2)*2/2:trunc((1920-ih)/2)*2/2:black[p2];[3:v]scale=trunc(min(iw*1920/ih\,1080)/2)*2:trunc(min(1920\,ih*1080/iw)/2)*2,setsar=1/1[scale4];
[scale4]pad=trunc(1080/2)*2:trunc(1920/2)*2:trunc((1080-iw)/2)*2/2:trunc((1920-ih)/2)*2/2:black[p3];
[0:a][1:a][2:a][3:a]concat=n=4:v=0:a=1[outa];
[7:a]afade=t=in:st=0:d=1[a];
[a]afade=t=out:st=5.00:d=1[a1];
[a1]volume=0.3[a2];[a2][outa]amix=inputs=2:duration=longest[finala];
[p0][p1][p2][p3]concat=n=4:v=1:a=0[outv];
[outv][4]overlay=x=20:y=main_h-overlay_h-20[subttv];
[5]scale=w=iw*oh/ih:min(ih\,180)[slogov2];
[subttv][slogov2]overlay=x=20:y=20[ovlv2];
[6]scale=w=iw*oh/ih:min(ih\,180)[slogov1];
[slogov1]lut=a=val*0.4[alphav];
[ovlv2][alphav]overlay=x='if(lte(ld(1),W-w)*gt(ld(1),0),st(1,ld(1)+1.00*ld(2)),if(eq(ld(2),0),st(2,1),st(2,(-1*ld(2))));if(eq(ld(2),1)+eq(ld(2),0),st(1,1),st(1,(W-w-1))))':y='if(lte(ld(3),H-h)*gt(ld(3),0),st(3,ld(3)+2.00*ld(4)),if(eq(ld(4),0),st(4,1),st(4,(-1*ld(4))));
if(eq(ld(4),1)+eq(ld(4),0),st(3,1),st(3,(H-h-1))))'[ovlv]"
-map "[ovlv]"
-map "[finala]"
-c:v libx264
-preset superfast
-nal-hrd cbr
-b:v 5554111
-minrate:v  5554111
-maxrate:v  5554111
-bufsize  11107822
-r 25
-minrate:a  128255
-t 6.00
-pix_fmt yuv420p
-y result.mp4

视频转码:

ffmpeg -hide_banner
-i a.mp4
-r 25
-c:v libx264
-preset fast
-nal-hrd cbr
-b:v 1700000
-minrate:v 1700000
-maxrate:v  1700000
-bufsize  3000000
-minrate:a  266000
-f mp4
-pix_fmt yuv420p
-y result.mp4

图片合成视频

ffmpeg -hide_banner
-t 10.00 -loop 1 -framerate 25 -i 1.jpg
-t 10.00 -loop 1 -framerate 25 -i 2.jpg
-stream_loop -1 -i musice.mp3
-i warning.png
-i logo.png
-i watermark.png
-filter_complex "[0][1]concat=n=2:v=1[outv];
[outv][3]overlay=x=main_w-overlay_w-20:y=main_h-overlay_h-20[subttv];[4]scale=w=iw*oh/ih:min(ih\,120)[slogov2];
[subttv][slogov2]overlay=x=20:y=20[ovlv2];
[5]scale=w=iw*oh/ih:min(ih\,120)[slogov1];
[slogov1]lut=a=val*0.4[alphav];
[ovlv2][alphav]overlay=x='if(lte(ld(1),W-w)*gt(ld(1),0),st(1,ld(1)+1.00*ld(2)),if(eq(ld(2),0),st(2,1),st(2,(-1*ld(2))));if(eq(ld(2),1)+eq(ld(2),0),st(1,1),st(1,(W-w-1))))':y='if(lte(ld(3),H-h)*gt(ld(3),0),st(3,ld(3)+2.00*ld(4)),if(eq(ld(4),0),st(4,1),st(4,(-1*ld(4))));
if(eq(ld(4),1)+eq(ld(4),0),st(3,1),st(3,(H-h-1))))'[ovlv];
[2:a]afade=t=in:st=0:d=1[a];
[a]afade=t=out:st=19.00:d=1[a1];
[a1]volume=0.3[a2]"
-map "[ovlv]"
-map "[a2]"
-c:v libx264
-preset superfast
-nal-hrd cbr
-b:v 1048776
-minrate:v  1048776
-maxrate:v  1048776
-bufsize  2097152
-r 25
-minrate:a  65556
-pix_fmt yuv420p
-y   -t 20 result.mp4

长图生成滚动视频:

ffmpeg -hide_banner
-t 76.798164
-loop 1
-r 25
-i imgBackground.png
-i longText.png
-filter_complex
"[0:v]crop=799:801:138:139:[crop1];
[crop1][1:v]overlay=x=0:y='if(gte(t,3),if(lte(y,H-h),H-h,y-1.875))'[outv]"
-map "[outv]"
-c:v libx264
-r 25
-x264-params "nal-hrd=cbr"
-b:v 2M
-minrate 2M
-maxrate 2M
-bufsize 4M
-y -t 76.798164 result.mp4