使用 ffmpeg 创建包含图像和音频文件的视频

使用 ffmpeg 创建包含图像和音频文件的视频

我想使用 ffmpeg 制作一个包含 jpeg 图像和 mp3 音频文件的简单视频。我使用了命令:

ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4

并收到此错误:

[swscaler @ 0x555f60538b40] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x555f60594d40] height not divisible by 2 (550x765)
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
Conversion failed!

我看不懂。你能帮我修改一下命令吗?

答案1

使用:

ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -vf "scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p" -shortest -movflags +faststart out.mp4

比例过滤器示例是一种使宽度和高度可以被 2 整除的奇特方法,这是该特定编码器在输出 YUV 4:2:0 时所需要的(大多数播放器不支持 4:2:2 和 4:4:4,所以这就是为什么你会看到这么多使用的示例yuv420p)。

一种更简单的方法是像 一样裁剪或缩放crop=550:764,但上述命令适用于任何输入尺寸。

相关内容