3

I'd like to achieve two things without re-encoding the whole video stream:

  1. Extend a video by freezing the last frame for a given duration.
  2. Extend a video by freezing a frame at a given timestamp for a given duration.

Currently I'm using ffmpeg -i in.mp4 -vf tpad=stop_mode=clone:stop_duration=5 out.mp4 but it requires encoding the whole video stream and only allows freezing the last frame of the stream. To get my desired result I need to split the video into segments, extract the last second of a segment to a separate file (so I re-encode just that part), run the above command on it and then merge all the segments back with concat demuxer.

Is there any better and simpler way to achieve the above?

1 Answers1

2

To 'extend' the the last frame, extend the audio stream by padding it.

ffmpeg -i in.mp4 -c:v copy -af apad -t 5 out.mp4

If there's no existing audio stream, add one

ffmpeg -i in.mp4 -f lavfi -i anullsrc -c:v copy -af apad -t 5 out.mp4

For pausing a frame in the middle with minimal re-encoding , segmenting + concat is indeed the way to go

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks a lot, Gyan! And if I wanted to actually modify the video track instead of adding a dummy audio track, is the `-vf tpad=stop_mode=clone:stop_duration=5 ` the correct approach? – user15180344 Feb 15 '21 at 05:10
  • 1
    Yes, tpad is the way to go. – Gyan Feb 15 '21 at 11:32
  • This is a brilliant solution! This works because when the video and audio are different lengths, it will extend the shorter stream to match the longer one by default (unless you use the `-shortest` option). – wisbucky Jun 09 '23 at 00:12
  • note that the `-t 5` argument is the length in seconds of the final output, not the length that you want to extend the input by. – wisbucky Jun 09 '23 at 00:14