13

I'm cutting/converting some videos with ffmpeg. What I'd really like is to be able to have the output hold the last frame for a few seconds (with silence for audio). Is such a thing possible? Or will I have to somehow get the last frame and make a new video from that?

4 Answers 4

13

The currently accepted answer is from 2014. The more recently added tpad filter lets you do this more easily.

ffmpeg -i in.mp4 -vf tpad=stop_mode=clone:stop_duration=2 out.mp4
1
10

One method is to use the overlay video filter. Assuming your video is 640x480, 30 seconds duration, 25 frame rate:

ffmpeg -f lavfi -i nullsrc=s=640x480:d=35:r=25 -i video.mp4 -i audio.wav -filter_complex \
"[0:v][1:v]overlay[video]" -map "[video]" -map 2:a -codec:a copy -shortest output.mkv
  • I set the duration of the nullsrc source filter to be 5 seconds longer than input.mkv.

  • The default behavior of overlay is to repeat the last frame of the overlaid source. See the eof_action option for other behaviors.

  • The audio in this example is being stream copied (re-muxed) instead of being re-encoded.

  • The downside is that this examples requires re-encoding since a filter is being used, but it may be simpler than other methods since it is just one command.

2
  • That sounds great - but can I do it if I'm also replacing the audio stream with a wav file? Also, do I need to know the size of the source video?
    – xorsyst
    May 30, 2014 at 8:43
  • 2
    @xorsyst Yes, you can replace the audio. I updated the example. Yes, this method requires that you know the frame size, duration, and frame rate of the source video, but all of these variables can be scripted. See FFprobe Tips.
    – llogan
    Jun 2, 2014 at 17:47
1

This solution is much faster because it does not require re-encoding.

If there already is an existing audio stream:

ffmpeg -i in.mp4 -vcodec copy -af apad -t 60 out.mp4

If there is NO existing audio stream:

ffmpeg -i in.mp4 -f lavfi -i anullsrc -vcodec copy -af apad -t 60 out.mp4
  • Note that the -t 60 refers to the length in seconds of the final output, not the seconds to extend it by.

  • The reason this works is because when the video and audio are different lengths, ffmpeg will extend the shorter stream to match the longer one by default (unless you use the -shortest option).

(credit Gyan)

0

I believe the answer to your question is "yes". I'm not super familiar with FFMPEG, but the easiest way I can see to accomplish your goal is to first extract the last frame to an image, make a video of a few seconds and then run an encode that concatenates the main video and your newly created video in one pass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.