9

To repeat the first frame of a video, for example padding it to compensate for longer audio, the following pipeline can be used.

ffmpeg -i video.mp4 -vframes 1 -f image2 image.jpg
ffmpeg -loop 1 -i image.jpg -t 5 pad.mkv
ffmpeg -i pad.mkv -i video.mp4 -i audio.mp3 -filter_complex '[0:v] [1:v] concat' -c:a copy -map 2:a out.mkv

(Concat filter preferred to concat input because codecs of video and padding clip may differ.)

In contrast, paddings audio with silence at the start fits in only one line.

ffmpeg -i video.mp4 -i audio.mp3 -map 0:v -filter_complex 'aevalsrc=0:duration=5 [pad],[pad] [1:a] concat=v=0:a=1' -c:v copy out.mkv

Can video padding be condensed in one ffmpeg execution, too?

XZS
  • 2,374
  • 2
  • 19
  • 38
  • 1
    I am aware of the `-itsoffet` switch. But it seems that this only affects time codes and inserts no real padding frames, which makes its use incompatible with some video players and encoders. For example, encoding flac with `-itsoffset` does not work. – XZS Sep 04 '13 at 07:02

1 Answers1

0

An old question, but you can use a loop-trim combo:

ffmpeg -i video.mp4 -i audio.mp3 \
  -filter_complex "[0:v]loop=loop=-1:size=1,trim=end=1[v0];\
                   [v0][0:v]concat" \
  -c:a copy -map 1:a out.mkv")

Specifying size=1 for the loop filter, only the first frame is selected. Since loop only specify its looping duration in terms of the number of loops, use the subsequent trim filter to stop the stream at the desired padding duration.

kesh
  • 4,515
  • 2
  • 12
  • 20