Merge videos and images using ffmpeg
ffmpeg
Solution
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.
Problem
I'm trying to compile one .webm file that contains this: - 10 seconds showing image1.jpg - Show a movie (an .mp4 file), which lasts about 20 seconds - 10 seconds showing image2.jpg - 10 seconds showing image3.jpg I was unable to find out how/if the concatenate functionality of ffmpeg could do such a thing. Any clues?