I'm trying to add my logo for the first 30 seconds in a video with ffmpeg. I have a video called d1.mp4 and a logo called logo.png.

When the video starts, the watermark should be at the top left or top right corner of the video and disappear after 30 seconds.

Can you please show me how to add it?

  • my video name is d1.mp4 and my logo name is logo.png ,thank you.. – iwocan Dec 4 '13 at 20:52
  • Then what does ffmpeg -i d1.mp4 -i logo.png show? Please just enter that command and show us what the output is. When asking questions about ffmpeg, you should always include as many details as possible about what video/audio material you have, what you already tried, and the full command line output of everything you have tried. – slhck Dec 4 '13 at 21:16
  • here's what i get on my cmd screen . pastebin.com/bPCnhXh2 – iwocan Dec 4 '13 at 21:27
up vote 12 down vote accepted
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.

  • 1
    Very Interesting! Could you explain why the framerate and loop are required in this case and not for a simple overlay without fade filter? – Rajib Dec 4 '13 at 16:25
  • Thank you very much mark40 but when i write this code, cmd screen doesn't stop.. I dont know why but it didnt work for me.. – iwocan Dec 4 '13 at 17:56
  • Hi LordNeckbeard, Here's a screenshot.. u1312.hizliresim.com/1j/4/v5ny8.png .. – iwocan Dec 4 '13 at 18:26
  • 1
    @iwocan I believe you can copy stuff out of the windows prompt. I assumed you would search how to do it, but look at Copy To the Clipboard From the Windows Command Prompt. – llogan Dec 4 '13 at 20:07
  • 4
    @Rajib: The reason for the -framerate and -loop for a still image is so that the fade out will work. If there is only a single frame then it has no way to fade out over a 1 second interval. Ideally it should be the same frame rate as the video so that the fade will be as smooth as possible. – mark4o Dec 4 '13 at 23:18

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.

  • Thank you very much! :) I apologize for my broken English again.This command works perfect! :) – iwocan Dec 4 '13 at 23:49
  • finally something understandable! what should i use to make it appear at the beginning than at the end? – cikatomo Oct 27 '15 at 0:14
  • I meant to appear at the beginning AND at the end? Two times. i have tried enable=between(t\,0\,30):enable=between(t\,50\,60) , but the only last timeline is in effect – cikatomo Oct 27 '15 at 2:40
  • @cikatomo enable=not(between'(t,30,50)'). This will show the overlay at all times but not at 30-60 seconds duration. – llogan Oct 27 '15 at 5:14
  • Perfect, thank you. Despite your warning to not use overlay all by itself, I did, because the default position of top left was what I wanted. (So in the end my flags were simply filter_complex overlay.) – felwithe May 6 '17 at 6:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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