使用ffmpeg和时间戳顺序将目录中的所有映像转换为.mp4 [英] Convert all images in directory to .mp4 using ffmpeg and a timestamp order

查看:488
本文介绍了使用ffmpeg和时间戳顺序将目录中的所有映像转换为.mp4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我发现一个解决方案,但它使用增量命名,如 image001 image002


$ b $我很欣赏任何帮助。谢谢。



使用aergistal的解决方案,我收到一个输出错误:
我按照你告诉我,但我得到一个输出错误:

 输入#0,concat,from'list.txt':
持续时间:N / A,开始:0.000000,比特率:N / A
流#0:0:视频:mjpeg,yuvj420p(pc,bt470bg / unknown / unknown),540x405 [SAR 1:1 DAR 4:3],25 tbr,25 tbn,25 tbc
[swscaler @ 0x14751c0]不建议使用的像素格式,请确保您正确设置了范围
[libx264 @ 0x14b7120]高度不可整除2(540x405)
输出#0,mp4,到'out.mp4 ':
流#0:0:视频:h264,无,q = 2-31,128 kb / s,SAR 1:1 DAR 0:0,30 fps
元数据:
编码器:Lavc56.26.100 libx264
流映射:
流#0:0 - > #0:0(mjpeg(native))> h264(libx264))
打开输出流#0的编码器时出错0 - 可能是不正确的参数,如bit_rate,rate,width或height


解决方案

按照您希望他们出现的顺序列出文件格式:



文件'< path / to / file>'



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

  ls /路径/到/ *。jpg |排序-V | xargs -I {} echofile'{}'> list.txt 

排序手册页:


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


示例列表:

 文件'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 


I have a directory with .jpg images named in UNIX timestamp format. How can I convert all images starting with the oldest timestamp to the newest in .mp4 video format?

I found a solution but it uses incremental naming, like image001, image002.

I would appreciate any help. Thanks.

Using aergistal's solution, i get an error in output: I did as you told me, but i get an output error:

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

解决方案

Make a list of files in the order in which you want them to appear using the format:

file '<path/to/file>'

On Linux you can fetch the files using the timestamp order and create the list using:

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

From the sort man page:

-V, --version-sort natural sort of (version) numbers within text

Example list:

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

Then use the FFmpeg concat demuxer with your list:

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

这篇关于使用ffmpeg和时间戳顺序将目录中的所有映像转换为.mp4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆