Merge videos and images using ffmpeg

前端 未结 1 1246
再見小時候
再見小時候 2021-01-03 05:26

I\'m trying to compile one .webm file that contains this:

  1. 10 seconds showing image1.jpg
  2. Show a movie (an .mp4 file), which lasts about 20 seconds
相关标签:
1条回答
  • 2021-01-03 06:22

    You can use the concat filter.

    Without audio

    ffmpeg \
    -loop 1 -framerate 24 -t 10 -i image1.jpg \
    -i video.mp4 \
    -loop 1 -framerate 24 -t 10 -i image2.jpg \
    -loop 1 -framerate 24 -t 10 -i image3.jpg \
    -filter_complex "[0][1][2][3]concat=n=4:v=1:a=0" out.mp4
    
    • Match -framerate with frame rate from video.mp4.

    With audio

    If there is audio in video.mp4 you'll need to provide audio for the images as well for it to be able to concatenate. Example of generating silence:

    ffmpeg \
    -loop 1 -framerate 24 -t 10 -i image1.jpg \
    -i video.mp4 \
    -loop 1 -framerate 24 -t 10 -i image2.jpg \
    -loop 1 -framerate 24 -t 10 -i image3.jpg \
    -f lavfi -t 0.1 -i anullsrc=channel_layout=stereo:sample_rate=44100 \
    -filter_complex "[0:v][4:a][1:v][1:a][2:v][4:a][3:v][4:a]concat=n=4:v=1:a=1" out.mp4
    
    • Match channel_layout with audio channel layout (stereo, mono, 5.1, etc) from video.mp4.
    • Match sample_rate with audio sample rate from video.mp4.
    • No need to match the -t duration from anullsrc with any associated video input: the concat filter will automatically pad it to match video duration.
    0 讨论(0)
提交回复
热议问题