MP4转为GIF
为GIF提取色板
ffmpeg -i a.mp4 -vf fps=15,scale=-1:-1::flags=lanczos,palettegen palette.png
转为固定高度960,帧速为15的GIF图片
ffmpeg -i a.mp4 -i palette.png -lavfi fps=15,scale=-1:960:flags=lanczos[x];[x][1:v]paletteuse -y a.gif
PNG转为JPG
为JPG提取色板
ffmpeg -i tempchart1.png -vf fps=15,scale=-1:-1::flags=lanczos,palettegen -y palette.png
转为固定宽度的JPG图片
ffmpeg -i tempchart1.png -i palette.png -lavfi scale=400:-1:flags=lanczos[x];[x][1:v]paletteuse -y tempchart1.jpg
视频添加音频
ffmpeg -stream_loop -1 -i xxx.mp3 -i xxx.mp4 -af afade=t=in:st=0:d=3,afade=t=out:st=${overtime}:d=3 -ss 00:00:00 -to ${endTimeStr} -y -b:v 1024k -profile:v main -brand mp42 out.mp4
视频中减去音轨
ffmpeg -i xxx.mp4 -an -y xx.mp4
使用硬件加速
ffmpeg -i xxxx.mp4 -c:v h264_nvenc -y xx.mp4
ffmpeg -i xxxx.mp4 -c:v h264_qsv -y xx.mp4
转为固定尺寸视频
ffmpeg -i xxxx.mp4 -s hd1080 -y xx.mp4
ffmpeg -i xxxx.mp4 -s hd720 -y xx.mp4
PNG转为带通道视频
ffmpeg -f concat -safe 0 -i input.txt -vcodec png aa.mov
ffmpeg -f concat -safe 0 -i input.txt -vcodec qtrle bb.mov
ffmpeg -i bb.mov -c:v libvpx-vp9 out.webm
ffmpeg -f concat -safe 0 -i input.txt -vcodec png -c:v libx264 aaa.mov
ffmpeg -f concat -safe 0 -i input.txt -vcodec qtrle -pix_fmt yuva420p bb.mov
视频裁剪
w、h为输出视频的宽和高,
x、y标记输入视频中的某点,将该点作为基准点,向右下进行裁剪得到输出视频。
如果x y不写的话,默认居中剪切
ffmpeg -i XX.mp4 -vf crop=400:400 XXX.mp4 -y
ffmpeg -i XX.mp4 -vf crop=400:400:0:0 XXX.mp4 -y
windows下 ffmpeg命令行批量转换视频
for %a in ("*.mp4") do ffmpeg -i "%a" -threads 2 -vcodec libx264 -preset slow -crf 20 -y "newfiles\%<sub>na.mp4"
for %%a in ("*.mp4") do ffmpeg -i "%%a" -threads 2 -vcodec libx264 -preset slow -crf 20 -y "%%</sub>na.mp4"