bash 使用 ffmpeg 和文件列表将图像序列转换为视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30188003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert image sequence to video using ffmpeg and list of files
提问by rensa
I have a camera taking time-lapse shots every 2–3 seconds, and I keep a rolling record of a few days' worth. Because that's a lot of files, I keep them in subdirectories by day and hour:
我有一台相机每 2 到 3 秒拍摄一次延时照片,并且我保留了几天的滚动记录。因为这是很多文件,我将它们按天和小时保存在子目录中:
images/
2015-05-02/
00/
2015-05-02-0000-02
2015-05-02-0000-05
2015-05-02-0000-07
01/
(etc.)
2015-05-03/
I'm writing a script to automatically upload a timelapse of the sunrise to YouTube each day. I can get the sunrise time from the web in advance, then go back after the sunrise and get a list of the files that were taken in that period using find
:
我正在编写一个脚本,每天自动将日出的延时摄影上传到 YouTube。我可以提前从网上获取日出时间,然后在日出后返回并使用find
以下命令获取该时期拍摄的文件列表:
touch -d "$SUNRISE_START" sunrise-start.txt
touch -d "$SUNRISE_END" sunrise-end.txt
find images/"$TODAY" -type f -anewer sunrise-start.txt ! -anewer sunrise-end.txt
Now I want to convert those files to a video with ffmpeg
. Ideally I'd like to do this without making a copy of all the files (because we're talking ~3.5 GB per hour of images), and I'd prefer not to rename them to something like image000n.jpg
because other users may want to access the images. Copying the images is my fallback.
现在我想将这些文件转换为带有ffmpeg
. 理想情况下,我希望在不复制所有文件的情况下执行此操作(因为我们说的是每小时约 3.5 GB 的图像),并且我不想将它们重命名为类似的名称,image000n.jpg
因为其他用户可能想要访问图片。复制图像是我的后备。
But I'm getting stuck sending the results of find
to ffmpeg
. I understand that ffmpeg can expand wildcards internally, but I'm not sure that this is going to work where the files aren't all in one directory. I also see a few people using find
's --exec
option with ffmpeg
to do batch conversions, but I'm not sure if this is going to work with image sequence input (as opposed to, say, converting 1000 images into 1000 single-frame videos).
但是我在发送find
to的结果时遇到了困难ffmpeg
。我知道 ffmpeg 可以在内部扩展通配符,但我不确定这是否会在文件不在一个目录中的情况下工作。我还看到一些人使用find
's--exec
选项ffmpeg
进行批量转换,但我不确定这是否适用于图像序列输入(而不是将 1000 个图像转换为 1000 个单帧视频)。
Any ideas on how I can connect the two—or, failing that, a better way to get files in a date range across several subdirectories into ffmpeg
as an image sequence?
关于如何将两者连接起来的任何想法 - 或者,如果失败,将跨多个子目录的日期范围内的文件ffmpeg
作为图像序列获取的更好方法?
回答by aergistal
Use the concat
demuxer with a list of files. The list format is:
将concat
demuxer 与文件列表一起使用。列表格式为:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Basic ffmpeg usage:
基本的ffmpeg用法:
`ffmpeg -f concat -i mylist.txt ... <output>`
Concatenate[FFmpeg wiki]
连接[FFmpeg wiki]
回答by aqn
ffmpeg probably uses the same file name globbing facility as the shell, so all valid file name globbing patterns should work. Specifically in your case, a pattern of images/201?-??-??/??/201?-??-??-????-??
will expand to all files in question e.g.
ffmpeg 可能使用与 shell 相同的文件名通配工具,因此所有有效的文件名通配模式都应该有效。特别是在您的情况下,模式images/201?-??-??/??/201?-??-??-????-??
将扩展到所有有问题的文件,例如
ls -l images/201?-??-??/??/201?-??-??-????-??
ffmpeg ... 'images/201?-??-??/??/201?-??-??-????-??' ...
Note the quotes around the pattern in the ffmpeg
invocation: you want to pass the pattern verbatim to ffmpeg
to expand the pattern into file names, not have the shell do the expansion.
请注意ffmpeg
调用中模式周围的引号:您希望逐字传递模式以将模式ffmpeg
扩展为文件名,而不是让 shell 进行扩展。