【问题标题】:Convert all images in directory to .mp4 using ffmpeg and a timestamp order使用 ffmpeg 和时间戳顺序将目录中的所有图像转换为 .mp4
【发布时间】:2015-07-19 05:10:40
【问题描述】:

我有一个目录,其中包含以 UNIX 时间戳 格式命名的 .jpg 图像。如何将所有以最旧时间戳开头的图像转换为.mp4 视频格式的最新图像?

我找到了一个解决方案,但它使用增量命名,例如 image001image002

如果有任何帮助,我将不胜感激。谢谢。

使用 aergistal 的解决方案,我得到一个输出错误: 我照你说的做了,但我得到一个输出错误:

Input #0, concat, from 'list.txt':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 540x405 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[swscaler @ 0x14751c0] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x14b7120] height not divisible by 2 (540x405)
Output #0, mp4, to 'out.mp4':
Stream #0:0: Video: h264, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 30 fps
Metadata:
  encoder         : Lavc56.26.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

【问题讨论】:

    标签: ffmpeg


    【解决方案1】:

    按照您希望它们出现的顺序使用以下格式制作文件列表:

    file '<path/to/file>'

    在 Linux 上,您可以使用时间戳顺序获取文件并使用以下命令创建列表:

    ls /path/to/*.jpg | sort -V | xargs -I {} echo "file '{}'" > list.txt
    

    来自sort 手册页:

    -V, --version-sort 文本中(版本)数字的自然排序

    示例列表:

    file '1.jpg'
    file '2.jpg'
    file '3.jpg'
    

    然后在您的列表中使用 FFmpeg concat demuxer

    ffmpeg -r 1/5 -f concat -i list.txt -c:v libx264 -r 25 -pix_fmt yuv420p -t 15 out.mp4
    

    【讨论】:

    • 感谢您帮助我! :) 我收到一个输出错误,我将其粘贴在问题描述中。
    • 实际上我解决了: ffmpeg -r 1/5 -f concat -i list.txt -c:v libx264 -r 30 -pix_fmt yuv420p -vf scale=540:-2 -t 15 out .mp4
    • 是的,图片尺寸应该是2的倍数
    • 但是,图像会在 5 秒后发生变化。是否可以在 1 秒内拥有 1-2 张图像?
    • @Jack 您还可以使用 concat demuxer 为每个图像添加持续时间(尽管对于图像我不确定它是否会忽略它)。也许值得尝试一下。请参阅docs
    猜你喜欢
    • 1970-01-01
    • 2015-07-27
    • 2016-08-03
    • 2015-09-03
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 2017-02-16
    相关资源
    最近更新 更多