如何从带有时间戳的图像列表中渲染视频? [英] How do I render a video from a list of time-stamped images?

查看:91
本文介绍了如何从带有时间戳的图像列表中渲染视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满图像的目录,该图像遵循模式<timestamp>.png,其中<timestamp>代表自第一个图像以来经过的毫秒数. input.txt包含有趣图像的列表:

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'
...

我正在使用ffmpeg将这些图像连接成视频:

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

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

我如何告诉ffmpeg将每一帧及时放置在其实际位置上,而不是使用恒定的帧速率?

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

推荐答案

遵循LordNeckbeard的建议,为ffmpeg的时间持续时间语法input.txt看起来像这样:

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'

现在ffmpeg处理可变的帧率.

Now ffmpeg handles the variable framerate.

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

这是构造input.txt的C#代码段:

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;
}

这篇关于如何从带有时间戳的图像列表中渲染视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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