How do I render a video from a list of time-stamped images?

柔情痞子 提交于 2019-12-04 00:04:17

问题


I have a directory full of images following the pattern <timestamp>.png, where <timestamp> represents milliseconds elapsed since the first image. input.txt contains a list of the interesting images:

file '0.png'
file '97.png'
file '178.png'
file '242.png'
file '296.png'
file '363.png'
...

I am using ffmpeg to concatenate these images into a video:

ffmpeg -r 15 -f concat -i input.txt output.webm

How do I tell ffmpeg to place each frame at its actual position in time instead of using a constant framerate?


回答1:


Following LordNeckbeard's suggestion to supply the duration directive to ffmpeg's concat demuxer using the time duration syntax, input.txt looks like this:

file '0.png'
duration 0.097
file '97.png'
duration 0.081
file '178.png'
duration 0.064
file '242.png'
duration 0.054
file '296.png'
duration 0.067
file '363.png'

Now ffmpeg handles the variable framerate.

ffmpeg -f concat -i input.txt output.webm

Here is the C# snippet that constructs input.txt:

Frame previousFrame = null;

foreach (Frame frame in frames)
{
    if (previousFrame != null)
    {
        TimeSpan diff = frame.ElapsedPosition - previousFrame.ElapsedPosition;
        writer.WriteLine("duration {0}", diff.TotalSeconds);
    }

    writer.WriteLine("file '{0}'", frame.FullName);
    previousFrame = frame;
}



回答2:


Appears your images are non standard frame rate...One option would be to duplicate the appropriate image "once per millisecond" [i.e. for

 file '0.png'
 file '97.png'

duplicate file 0.png 96 times, so it becomes 0.png 1.png 2.png etc. (or use symlinks, if on linux).

Then you can combine them using the normal image inputter [with input rate of 1ms/frame]. https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images



来源:https://stackoverflow.com/questions/25073292/how-do-i-render-a-video-from-a-list-of-time-stamped-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!