How to add my logo for the first 30 seconds in a video with ffmpeg?

Using overlay video filter to add a logo to a video:

enter image description here

ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay" \
-codec:a copy out.mp4

To understand this command you need to know what a stream specifier is and reading the Introduction to FFmpeg Filtering will help. [0:v] refers to the video stream(s) of first input (video.mp4), and [1:v] refers to the video stream of the second input (logo.mp4). This is how you can tell overlay what inputs to use. You can omit [0:v][1:v], and overlay will still work, but it is recommended to be explicit and not rely on possibly unknown defaults.

By default the logo will be placed in the upper left.

Using -codec:a copy will stream copy the audio. This simply re-muxes the audio instead of re-encoding it. Think of it as a "copy and paste" of the audio.

Moving the logo

This example will move the logo 10 pixels to the right, and 10 pixels down: enter image description here

ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=10:10" \
-codec:a copy out.mp4

This example will move the logo 10 pixels from the right side and 10 pixels down:

enter image description here

ffmpeg -i video.mp4 -i logo.png -filter_complex \
"[0:v][1:v]overlay=main_w-overlay_w-10:10" -codec:a copy out.mp4

main_w refers to the width of the "main" input (the background or [0:v]), and overlay_w refers to the width of the "overlay" input (the logo or [1:v]). So, in the example, this can be translated to overlay=320-90-10:10 or overlay=220:10.

Timing the overlay

Some filters can handle timeline editing which allows you to use arithmetic expressions to determine when a filter should be applied. Refer to ffmpeg -filters to see which filters support timeline editing.

This example will show the logo until 30 seconds:

ffmpeg -i video.mp4 -i logo.png -filter_complex \
"[0:v][1:v]overlay=10:10:enable=between(t\,0\,30)" -codec:a copy out.mp4

If you want to fade the logo refer to mark4o's answer.


ffmpeg -i in.mp4 -framerate 30000/1001 -loop 1 -i logo.png -filter_complex
  "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; [0:v][ov] overlay=10:10 [v]" -map "[v]"
  -map 0:a -c:v libx264 -c:a copy -shortest out.mp4

This assumes that the logo is a single still image with an alpha channel and you want to overlay it over a video with a frame rate of 30000/1001 (NTSC rate). Change the -framerate to match your input video if it is different. If your logo is a video then omit -framerate 30000/1001 -loop 1. If the logo does not have an alpha channel, add one by inserting e.g. format=yuva420p, immediately before fade.

This will display the logo at x,y position 10,10 for 30 seconds followed by a 1 second fade out.

Tags:

Ffmpeg