ffmpeg - extend last video frame duration
I needed this last week and will probably need it again soon, so here's a public note to myself.
Again ffmpeg proves his strengths.
Count frames:
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of csv=p=0 test.mp4
Outputs video frames count - for example:
125
Extract last frame - zero-indexed (or really any frame):
ffmpeg -i test.mp4 -vf "select='eq(n\,124)'" -vsync 0 -vframes 1 frame.png
Make 2 sec (or desired time -t) video from frame:
ffmpeg -loop 1 -i frame.png -c:v libx264 -t 2 -pix_fmt yuv420p -vf "fps=30" frame_video.mp4
Create a files.txt
files that contains list of files concat:
touch files.txt
echo "file 'test.mp4'" >> files.txt
echo "file 'frame_video.mp4'" >> files.txt
Concat videos from files.txt
into a single output video:
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4
Last frame of output.mp4 video now lasts for 2 seconds at the end.
There's maybe a better way to do it, but I found this useful enough for myself and adjusting the commands allows for flexibility, if other frames are to be extended in duration.