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

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

问题描述

我有一个目录,里面有一个遵循模式 .png 的图像,其中 表示从第一张图像开始经过的毫秒数.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 的建议,将 duration 指令提供给 ffmpeg 的 concat demuxer 使用 持续时间语法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天全站免登陆