ffmpeg 压缩视频,两个报错

把分辨率缩小一倍,其它不变,由130M压缩到16M,效果还可以.
影响压缩的参数,码率=文件大小(KB)*8/播放长度s.

第一个报错
./ffmpeg.exe -i qhkj2.mp4 scale=1639:819 v1.mp4
报错:
[NULL @ 00000259c852ed40] Unable to find a suitable output format for ‘scale=1639:819’
scale=1639:819: Invalid argument

原因:You need to enter -vf before scale to tell FFmpeg that you want to use a video filter. Also, it should be specified after the filename of the image as it’s an output option, not an input option. You can put it just before the output name:
大概的意思是说,你需要在scale参数前面输入-vf参数,用来告知ffmpeg,需要使用video的过滤器,-vf应该放到视频文件名后面,-vf是一个输出视频的选项,不是导入视频的选项,把-vf放到输出视频的名字前面,例如v1.mp4前面,如下
解决办法:
./ffmpeg.exe -i qhkj2.mp4 -vf scale=1639:819 v1.mp4

第二个报错
./ffmpeg.exe -i qhkj2.mp4 -vf scale=1639:819 v1.mp4
报错:
[libx264 @ 0000027ff8717a00] width not divisible by 2 (1639×819)
Error initializing output stream 0:0 — Error while opening encoder for output stream #0:0 – maybe incorrect parameters
such as bit_rate, rate, width or height
[aac @ 0000027ff8521180] Qavg: 139.243
[aac @ 0000027ff8521180] 2 frames left in the queue on closing

原因:
出现该错误的原因是在于:视频的宽度必须是32的倍数,高度必须是2的倍数
解决方法:
if (screen_width % 32 != 0)
{
screen_width = screen_width / 32 * 32;
}
if (screen_height % 2 != 0)
{
screen_height = screen_height / 2 * 2;
}
最终命令:./ffmpeg.exe -i qhkj2.mp4 -vf scale=1632:820 v1.mp4
成功.

发表评论

您的电子邮箱地址不会被公开。