全局

全局

我是 ffmpeg 的初学者。

我想将几张图片转换为幻灯片,并想出了这个命令:

ffmpeg -y -r 1/5 -i *.jpg -r 25 output.mp4

相当直观。但是,视频似乎只有一帧长(速度太快,我没法识别)

以下是上述命令的输出:

    ffmpeg version 0.8.9-4:0.8.9-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Nov  9 2013 19:12:07 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, image2, from 'swirl3777.jpg':
  Duration: 00:00:05.00, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: mjpeg, yuvj444p, 1600x1200 [PAR 72:72 DAR 4:3], 0.20 tbr, 0.20 tbn, 0.20 tbc
Incompatible pixel format 'yuvj444p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x86e2040] w:1600 h:1200 pixfmt:yuvj444p
[avsink @ 0x86e8920] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x86e8d80] w:1600 h:1200 fmt:yuvj444p -> w:1600 h:1200 fmt:yuvj420p flags:0x4
Incompatible pixel format 'yuvj444p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x86e8c00] w:1600 h:1200 pixfmt:yuvj444p
[avsink @ 0x87159a0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x86f1860] w:1600 h:1200 fmt:yuvj444p -> w:1600 h:1200 fmt:yuvj420p flags:0x4
Incompatible pixel format 'yuvj444p' for codec 'mpeg4', auto-selecting format 'yuv420p'
[buffer @ 0x86f17c0] w:1600 h:1200 pixfmt:yuvj444p
[avsink @ 0x870f4a0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x8737e60] w:1600 h:1200 fmt:yuvj444p -> w:1600 h:1200 fmt:yuv420p flags:0x4
Output #0, image2, to 'swirl3786.jpg':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: mjpeg, yuvj420p, 1600x1200 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 0.20 tbc
Output #1, image2, to 'swirl3787.jpg':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #1.0: Video: mjpeg, yuvj420p, 1600x1200 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 0.20 tbc
Output #2, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #2.0: Video: mpeg4, yuv420p, 1600x1200 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.0 -> #1.0
  Stream #0.0 -> #2.0
Press ctrl-c to stop encoding
frame=    1 fps=  0 q=10.2 Lq=10.2 q=9.5 size=      -0kB time=0.04 bitrate=  -4.4kbits/s    
video:584kB audio:0kB global headers:0kB muxing overhead -100.003680%

我也尝试了 avconv,但输出相同,文件大小也相同。如果我将 -r 值更改为 3434321 等荒谬的值,文件大小仍然相同。如果我添加 -b 512k 或 -b 1024,文件大小仍然相同……似乎选项在某种程度上被忽略了。

文件夹中的三张图片均被正确检测。

像素格式不兼容有什么问题吗?

我这里是Ubuntu 12.04 ffmpeg版本0.8.9-4:0.8.9-0ubuntu0.12.04.1

猜猜我可能做错了什么?TIA

答案1

全局

ffmpeg来自 FFmpeg 的支持全局模式因此,您的输入文件几乎可以命名为任何名称,只要它们符合您想要的顺序即可:

ffmpeg -framerate 1/5 -pattern_type glob -i "*.jpg" -vf "fps=25,format=yuv420p" out.mp4

Ubuntu 使用Libav(FFmpeg 的一个分支)中avconv存在缺陷的假“ ffmpeg”,并且不支持 glob 模式。请参阅谁能告诉我ffmpeg,libav和avconv之间的区别和关系?

得到ffmpeg

要获得ffmpeg,你可以简单地下载 Linux 版本ffmpeg或关注一步一步指导编译ffmpeg


潜在问题

跳过第一张图片

存在一些未解决的问题或不一致之处,-r涉及fps视频滤镜。有时,第一个输入图像似乎被跳过或仅显示一帧。您可以使用fps过滤器来避免跳过问题,如我上面的示例所示。查看票证第 1578 章#3164了解更多信息。

跳过最后一张图片

可能会出现最后一幅图像被跳过或只显示一帧的情况。我没有找到解决此问题的好办法,但您可以简单地复制最后一幅图像文件来进行补偿。

甚至更多跳过

如果您输入的图像并非都具有相同的像素格式和/或帧大小,则ffmpeg可能会跳过不确定数量的帧。请确保所有输入图像都相似以避免这种情况。您可以看到控制台输出,其中会提到任何输入文件的差异。

输出的 MP4 视频无法播放

使用不太差的播放器,或者使用format我示例中所示的过滤器,或者使用-pix_fmt yuv420p输出选项。否则ffmpeg将尝试避免或最小化色度二次采样(取决于您的输入、您使用的编码器、您的ffmpeg版本以及您使用的编码选项),虽然这在技术意义上可能很好,但它可能会创建非基于 FFmpeg 的播放器无法播放的输出。

答案2

尝试这个:

ffmpeg -y -f image2 -r 1/5 -i img%03d.jpg -pix_fmt yuv420p -r 25 output.mp4  

您的 jpeg 必须按 img001.jpg...img009.jpg 格式按顺序编号。%03d代表 3 位数字序列 - 以 2 个前导零开头。如果您有 img01.jpg 到 img 09.jpg,则可以使用img%02d.jpg。该*.jpg语法不起作用。

相关内容