Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
793 views
in Technique[技术] by (71.8m points)

ffmpeg - ffmepg video from uneven sequence of png images

I'm going to make a video from series of screenshots (.png files). For each screenshot there is assosiated timestamp information about when it was taken. The time intervals between screenshots may vary and it's highly desired to preserve that difference in the video.

Is there a way to use single ffmpeg command/API providing to it sequence of image + time (or frame) offset and getting one video file as output? By now I have to generate short video files of custom length for each image, and then merge them manually:

ffmpeg -y -loop 1 -i image1.png -c:v libx264 -t 1.52 video1.avi
ffmpeg -y -loop 1 -i image2.png -c:v libx264 -t 2.28 video2.avi
...
ffmpeg -y -loop 1 -i imageN.png -c:v libx264 -t 1.04 videoN.avi


ffmpeg -i "concat:video1.avi|video2.avi|...videoN.avi" -c copy output.avi

This is quite ok, while intervals are large, but the whole approach seems to me a bit fragile.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the concat demuxer.

enter image description here
Example using 2, 4, and 0.25 seconds.

  1. Make a text file indicating the desired duration per file:

    file 'image1.png'
    duration 1.52
    file 'image2.png'
    duration 2.28
    file 'image3.png'
    duration 1.04
    

    You may have to repeat the last file and duration lines to get it to display the last frame.

  2. Run the ffmpeg command:

    ffmpeg -f concat -i input.txt -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...