written by
Alan Richardson

How to create a video with an image at the end using ffmpeg

talotics.com 2 min read

Having created a video, I want a call to action image that plays after the video is complete, and I want this to be standardised for a lot of my videos.

I can do that with ffmpeg

Previous posts have covered ffmpeg for helping with video marketing.

I now know how to create videos for various sites. Ideally I want a post roll video which links to my site.

I could create a video for that, but to make it easier to change I’m going to use a single image that displays for a few seconds.

Create a video from an image

I can create a 5 second video from a png as follows:

Remember when you type it in, all lines will be on a single line.

ffmpeg -loop 1 -i image.png
-pix_fmt yuv420p -t 5
promo-image.mp4

This will create a video called ‘promo-image.mp4’ with a duration of 5 seconds.

I will want to control the size of the video so that when I join them they are the same dimensions, I can do that in a single command.

ffmpeg -loop 1 -i image.png
-pix_fmt yuv420p -t 5
-vf scale=1920:1080
promo-image.mp4

It doesn’t matter what size the image was previously, the video will be 1920 x 1080 pixels.

I found that when concatenating the videos, I needed to add a silent audio track otherwise the videos would not concatenate, so the following is the command I used to create my post roll video.

ffmpeg -f lavfi
-i anullsrc=channel_layout=stereo:sample_rate=44100
-loop 1 -i image.png
-pix_fmt yuv420p -t 5
-vf scale=1920:1080
promo-image.mp4

Concatenate videos

I can join any number of videos together, but in this case I’m just combining two:

ffmpeg -i video.mp4 -i promo-image.mp4
-filter_complex
"[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]"
-map "[outv]" -map "[outa]"
video-with-promo.mp4

If I wanted more videos I would add them as -i anothervid.mp4 and I would have to change the filter complex definition

e.g. "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]"

Better for distribution

And with this I can have a call to action in the final slide, as well as in the video description because there is no guarantee that people actually read the video descriptions.

Useful links

You can find the commands in an easy to copy and past format in this gist page

videos