I have on one side a video (of someone giving a talk) and on the other side a list of slides that were used, and the timing at where the slides were switched. I want to embed the slides in a resulting video. Do you know how to do this?

I've found how to do it with one image, but I don't know if it's possible to do it with multiple ones?

ffmpeg -i input.mp4 -i image.png \ -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \ -pix_fmt yuv420p -c:a copy \ output.mp4


You can chain multiple overlay filters where each instance overlays one slide, but this will very quickly produce an unwieldy command. It's more convenient to do this in two steps. 1) Generate a video of the slides only with the required timings. 2) Use a simple ffmpeg command to overlay that video onto the main video.

For the first step, I've pasted an earlier answer I gave:

You can use a combination of two tools to do this: ffmpeg and mp4fpsmod

Step 1 is to generate a constant frame rate file using ffmpeg

ffmpeg -i images%d.bmp -pix_fmt yuv420p ffmpeg-cfr.mp4

Step 2 is to generate a timecode file like the one below, with each line containing the relative timestamp for a frame in milliseconds.

# timecode format v2


Step 3 is to use mp4fpsmod to generate the VFR file

mp4fpsmod -o vfr.mp4 -t timecodes.txt ffmpeg-cfr.mp4 

This file plays as expected with ffplay but may not with some players, in which case run

Step 4 Generate a CFR MP4 from the VFR using FFmpeg

ffmpeg -i vfr.mp4 final-cfr.mp4

This is a CFR file but the temporal relations are preserved as per the VFR, although there will be some PTS adjustments, if the timecode intervals are very irregular. That can be remedied by specifying a high framerate -r N

You'll have to rename your slide images so that their names form a continuous regular sequence. And for your case, I'd suggest your Step 1 command should be

ffmpeg -i images%d.png -c:v libx264rgb -pix_fmt rgb24 ffmpeg-cfr.mp4

and Step 4 if needed should be

ffmpeg -i vfr.mp4 -crf 16 -c:v libx264rgb final-cfr.mp4

You can then overlay the latest file onto the lecture video, using a command like the one in your question.

| improve this answer | |
  • Thanks for your answer. I tried, but during the last step, I'm not sure how I should use the command you're reffering to. Here is what I tried but the slids aren't showing for a few seconds in the resulting video: ffmpeg -i "Video name-WUUc5HYE3yY.mp4" -i final-cfr.mp4 -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,5)'" -pix_fmt yuv420p -c:a copy output.mp4. What should I do instead? – Alexis Métaireau Nov 3 '16 at 23:00
  • What's the first value in your timecode text file? – Gyan Nov 4 '16 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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