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

后端 未结 2 1776
失恋的感觉
失恋的感觉 2021-01-11 13:12

I have a directory full of images following the pattern .png, where represents milliseconds elapsed since the fi

2条回答
  •  感情败类
    2021-01-11 13:56

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

提交回复
热议问题