宝塔山 发表于 2024-12-15 17:38:49

ffmpeg和ffplay下令行实战手册

视频拼接用concat

n
设置分段数。默认值为2。
v
设置输出视频流的数量,也就是每个片断中视频流的数量。默认值为1。
a
设置输出音频流的数量,也就是每个片断中音频流的数量。默认值为0。
一定要注意n v a的数量
视频分段拼接(ffplay 不可调用seek函数进行seek)

注意:一定是vavava 而不是vvvaaa,否则GG
ffmpeg:
ffmpeg -i C:/Users/CY/Desktop/video4_540_960.mp4 -i C:/Users/CY/Desktop/video5_540_960.mp4
-i C:/Users/CY/Desktop/video6_540_960.mp4 -filter_complex
"concat=n=3:v=1:a=1"
-map "" -map "" C:/Users/CY/Desktop/videoddddddddddd.mp4
一定要写setsar= 1/1,否则分辨率不同等的时候GG如下:
Input link in1:v0 parameters (size 720x1282, SAR 1:1) do not match the corresponding output
link in0:v0 parameters (720x1280, SAR 1:1)
ffplay:
ffplay -f lavfi "movie=C\\:/Users/CY/Desktop/video4_540_960.mp4,setsar= 1/1;
movie=C\\:/Users/CY/Desktop/video5_540_960.mp4,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video4_540_960.mp4;
amovie=C\\:/Users/CY/Desktop/video5_540_960.mp4;
concat=2:v=1:a=1"
ffplay:
ffplay -f lavfi "movie=C\\:/Users/CY/Desktop/video4_540_960.mp4,setsar= 1/1;
movie=C\\:/Users/CY/Desktop/video5_540_960.mp4,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video4_540_960.mp4;
amovie=C\\:/Users/CY/Desktop/video5_540_960.mp4;
concat=n=2:v=1:a=0;
concat=n=2:v=0:a=1"
拼接3段视频
ffplay:
ffplay -f lavfi "movie=C\\:/Users/CY/Desktop/video4_540_960.mp4,setsar= 1/1;
movie=C\\:/Users/CY/Desktop/video5_540_960.mp4,setsar= 1/1;
movie=C\\:/Users/CY/Desktop/video6_540_960.mp4,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video4_540_960.mp4;
amovie=C\\:/Users/CY/Desktop/video5_540_960.mp4;
amovie=C\\:/Users/CY/Desktop/video6_540_960.mp4;
concat=n=3:v=1:a=1"
给视频添加黑边,让视频添补并居中显示

ffmpeg:
ffmpeg -f lavfi -i movie=C\\:/Users/CY/Desktop/video4_540_960.mp4,
scale=270:480,pad=540:960:(ow-iw)/2:(oh-ih)/2:black;
amovie=C\\:/Users/CY/Desktop/video4_540_960.mp4   
C:\Users\CY\Desktop\out.mp4
iw ow
ffmpeg -y -i C:\Users\CY\Desktop\0.mp4 -i C:\Users\CY\Desktop\1.mp4 -filter_complex
"scale='if(gte(iw/ih,1),1080,-1)':'if(gte(iw/ih,1),-1,1920)',
pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black;
scale='if(gte(iw/ih,1),1080,-1)':'if(gte(iw/ih,1),-1,1920)',
pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black;
concat=n=2:v=1:a=1" -map -map C:\Users\CY\Desktop\out.mp4
不同分辨率视频分段拼接,而且,设置单个视频的缩放比例和摆放位置

给视频上下左右添加50像素黑边
scale:将视频缩小到620*476,给即将添加的黑边预留像素
pad: “宽”、“高”、“X坐标”和“Y坐标”,宽和高指的是输入视频尺寸(包含加黑边的尺寸),XY指的是视频地点位置
ffmpeg -i test.ts -vf "scale=620:476,pad=720:576:50:50:black" test.mp4
C:/FFMPEG/ffmpeg_x86_4.2.2/bin/ffmpeg.exe -i D:/123.mp4 -vf
"scale=100:100,pad=500:500:0:300:black" D:/linux-share-dir/video_file/output.mp4
参数表明:
100:100 视频帧在画布里的尺寸–按比例缩放的. (w:h)
500:500 画布的尺寸 . (w:h)
0:300 视频帧在画面上的位置. (x:y)
black 画布的背景颜色
ffplay:
ffplay-f lavfi "movie=C\\:/Users/CY/Desktop/video.mp4,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video.mp4;
movie=C\\:/Users/CY/Desktop/video5_540_960.mp4, crop=iw:ih/2;
scale=1080*iw/ih:1080,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video5_540_960.mp4;
movie=C\\:/Users/CY/Desktop/mp4.mp4, pad=1920:1080:0:300:black,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/mp4.mp4;
concat=n=3:v=1:a=1"
视频画中画复杂嵌套用overlay(ffplay 可调用seek函数进行seek)

ffplay:
ffplay -x 600 -i C:/Users/CY/Desktop/video.mp4 -vf
"movie=C\\:/Users/CY/Desktop/gx.mp4;overlay=100:100"
-af "amovie=C\\:/Users/CY/Desktop/gx.mp4;amix"
ffmpeg:
ffmpeg -y -i C:/Users/CY/Desktop/video.mp4 -vf
"movie=C\\:/Users/CY/Desktop/gx.mp4;overlay=100:100"
-af "amovie=C\\:/Users/CY/Desktop/gx.mp4;amix"
C:\Users\CY\Desktop\outttttttt.mp4
视频画中画复杂嵌套用overlay(ffplay 不可调用seek函数进行seek)

ffplay:
ffplay -f lavfi "movie=C\\:/Users/cy/Desktop/video.mp4;
amovie=C\\:/Users/cy/Desktop/video.mp4;
movie=C\\:/Users/cy/Desktop/mp4.mp4;
amovie=C\\:/Users/cy/Desktop/mp4.mp4;
movie=C\\:/Users/cy/Desktop/video4_540_960.mp4,scale=512:288;
amovie=C\\:/Users/cy/Desktop/video4_540_960.mp4;
overlay=100:100;
overlay=200:200;
amix;amix"
视频拼接+视频画中画复杂嵌套(ffplay 不可调用seek函数进行seek)

out0 out1又可作为输入
ffplay:
ffplay-f lavfi "movie=C\\:/Users/CY/Desktop/video.mp4,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video.mp4;
movie=C\\:/Users/CY/Desktop/video5_540_960.mp4,crop=iw:ih/2;
scale=1080*iw/ih:1080,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/video5_540_960.mp4;
movie=C\\:/Users/CY/Desktop/mp4.mp4, pad=1920:1080:0:300:black,setsar= 1/1;
amovie=C\\:/Users/CY/Desktop/mp4.mp4;
concat=n=3:v=1:a=1;
movie=C\\:/Users/cy/Desktop/mp4.mp4;
amovie=C\\:/Users/cy/Desktop/mp4.mp4;
overlay=100:100;
amix"
视频精准seek

ffmpeg截取帧为图片

ffmpeg -y -f lavfi -i movie=C\\:/Users/CY/Desktop/1658673245.mp4,setsar=1/1;
amovie=C\\:/Users/CY/Desktop/1658673245.mp4;
movie=C\\:/Users/CY/Desktop/bb.mp4,scale=64:36,pad=64:36:(ow-iw)/2:(oh-
ih)/2:black,setsar=1/1;
amovie=C\\:/Users/CY/Desktop/bb.mp4;
overlay=100:100;amix
-ss 00:00:20 -t 1 -r 3 -q:v 2 -f image2C:/Users/CY/Desktop/foo-%05d.jpeg
ffplay seek_point

ffplay-flavfi   "movie=C\\:/Users/CY/Desktop/video.mp4:seek_point=8.337878;
amovie=C\\:/Users/CY/Desktop/video.mp4:seek_point=8.337878"
ffplay:
ffplay -f lavfi "movie=C\\:/Users/cy/Desktop/video.mp4:seek_point=8;
amovie=C\\:/Users/cy/Desktop/video.mp4:seek_point=8;
movie=C\\:/Users/cy/Desktop/mp4.mp4::seek_point=8;
amovie=C\\:/Users/cy/Desktop/mp4.mp4::seek_point=8;
movie=C\\:/Users/cy/Desktop/video4_540_960.mp4::seek_point=8,scale=512:288;
amovie=C\\:/Users/cy/Desktop/video4_540_960.mp4::seek_point=8;
overlay=100:100;
overlay=200:200;
amix;
amix"
视频到放 reverse areverse

ffplay:
ffplay -x 500 -flavfi
"movie=C\\:/Users/CY/Desktop/video4_540_960.mp4:seek_point=0,reverse;
amovie=C\\:/Users/CY/Desktop/video4_540_960.mp4:seek_point=0,areverse"
ffplay:
ffplay -x 600 -f lavfi "movie=C\\:/Users/cy/Desktop/video.mp4:seek_point=8,reverse;
amovie=C\\:/Users/cy/Desktop/video.mp4:seek_point=8,areverse;
movie=C\\:/Users/cy/Desktop/mp4.mp4:seek_point=8,reverse;
amovie=C\\:/Users/cy/Desktop/mp4.mp4:seek_point=8,areverse;
movie=C\\:/Users/cy/Desktop/video4_540_960.mp4:seek_point=8,scale=512:288,reverse;
amovie=C\\:/Users/cy/Desktop/video4_540_960.mp4:seek_point=8,areverse;
overlay=100:100;
overlay=200:200;
amix;
amix"
GIF编解码

png图片合成GIF:
ffmpeg -i C:\Users\CY\Desktop\%d.png -vf palettegen C:\Users\CY\Desktop\palette.png
ffmpeg-framerate 2 -i C:\Users\CY\Desktop\%d.png
-i C:\Users\CY\Desktop\palette.png -lavfi paletteuse C:\Users\CY\Desktop\out.gif
先给所有png图片天生一个调色板PNG图片,然后再利用调色板PNG图片合成带透明度的GIF图片,否则有色差或者无透明度。注意:是所有和一个,不能是所有和所有,只能有一个调色板PNG图片,否则还是有色差。
天生高质量GIF

1.默认配置+关闭抖动
ffmpeg -i C:\Users\CY\Desktop\相框.mp4 -vf
"fps=10,scale=480:-1:flags=lanczos,split;palettegen;
paletteuse=dither=none" C:\Users\CY\Desktop\相框.gif
这个方式已经是最好的,用全局调色板(用单个调色板,反而色带更严峻,编码也更久),关门抖动(否则很容易出现色差和网格)
输出RGB数据

ffmpeg -i C:\Users\CY\Desktop\bjz.gif -vf "format=rgb24" -f image2
C:\Users\CY\Desktop\bjz\bjz_output%d.rgb
播放RGB数据

ffplay -pixel_format rgb24 -video_size 480x856 -i C:\Users\CY\Desktop\bjz41.rgb
必须指定分辨率,否则花屏或者报错0x0 invalid
音视频倍速

ffmpeg -y -i C:\Users\CY\Desktop\相框.mp4 -r 25*4 -filter_complex
"setpts=1/4*PTS;atempo=4.0" -map "" -map ""
C:\Users\CY\Desktop\相框2.mp4
注意:音频倍速和视频倍速是分开写的,想降低视频的总时长,音频也是要增速的,如果盼望不丢帧,则设置精确的帧率
天生圆角矩形图片

ffmpeg -y -i C:\Users\CY\Desktop\mn.jpg -frames:v 1-filter_complex "
format=rgba,geq=lum='p(X,Y)':a='if(gt(abs(W/2-X),W/2-200)*gt(abs(H/2-Y),H/2-200),
if(lte(hypot(200-(W/2-abs(W/2-X)),200-(H/2-abs(H/2-Y))),200),255,0),255)'"
C:\Users\CY\Desktop\example.png
天生圆形图片

ffmpeg -y -i C:\Users\CY\Desktop\mn.jpg -vf
"format=yuva420p,geq=lum='p(X,Y)':a='if(lt(sqrt((X-3648/2)^2+(Y-
5472/2)^2),3648/2),255,0)'"
C:\Users\CY\Desktop\mn_yj.png
中文文字天生PNG图片

ffmpeg -y -f lavfi -i "color=c=0x00000000:s=300x100,drawtext=text='快乐体':fontfile=C\\:/Users/CY/Desktop/ZCOOL_KuaiLe/ZCOOLKuaiLe-Regular.ttf:fontsize=100:fontcolor=#ffffffdd:x=(w-text_w)/2:y=(h-text_h)/2,format=rgba" -frames:v 1 C:\Users\CY\Desktop\ZCOOL_KuaiLe\ZCOOLKuaiLe-Regular.png
注意:指定fontfile路径时,:号必须用\\转义,路径不能用\,必须/,纵然''包起来和\\转义也不行,否则乱码,由于路径指定有误,ffmpeg无法找到字库。文字颜色必须是rgba,RRGGBBAA排序。不能写argb然后幻想AARRGGBB

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: ffmpeg和ffplay下令行实战手册