Reputation: 10713
I have 49 rendered frames of png. I convert these frame to a video usingffmpeg
:
ffmpeg -r 24 -f image2 -s 1920x1080 -i %04d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p test2.mp4
However this just makes a sequence of all the frames. Now I try to achieve the following sequence:
frame 1...24 - frame 25 - frame 26...49
When frame 25 need to be repeated for 120 frames. Is this possible with ffmpeg
?
It would be even better if it is possible to achieve:
frame 1...24 - frame 25 - frame 24...1
Upvotes: 1
Views: 1949
Reputation: 93018
Assuming you're working with the 50 frame sequence,
ffmpeg -framerate 24 -i %04d.png
-filter_complex "[0]trim=end_frame=25,split=2[fo][re];[fo]loop=118:1:24,setpts=N/24/TB[fo];
[re]reverse,setpts=N/24/TB[re];[fo][re]concat=n=2:v=1:a=0"
-c:v libx264 -crf 25 -pix_fmt yuv420p out.mp4
[0]trim=end_frame=25
--> keep the first 25 frames. Frames are numbered starting with 0.
split=2[fo][re]
--> have two copies of this trimmed segment
[fo]loop=118:1:24
--> Loop the single frame 1
at the end 24
118
times. So there's 119 instances of the last frame.
setpts=N/24/TB[fo]
--> long story short, ffmpeg is meant to work with timed media, so this filter is to make sure the segment now with the loop has smooth, continuous timestamps. 24
is the framerate of the input.
[re]reverse
--> reverse the 2nd copy of the trimmed segment.
setpts=N/24/TB[re]
--> same as above.
[fo][re]concat=n=2:v=1:a=0
--> join the two segments - the looped one, and the reversed one. Since the 25th frame is the first frame of the reversed sequence, there's 120 instances of the 25th frame.
Upvotes: 6