Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm making a video for YouTube, and I've already edited and touched it up in a full video editing program. The last thing I want to do is add an overlay banner with subscribe and playlist buttons which I'll turn into annotations. I want this to appear for the first 5 seconds of the video. Unfortunately my full video editing program can't due that, so I'd like to use FFMPEG to achieve this effect.

I've seen a few tutorials about this (this one in particular seemed pretty good), but none of them mention how to specify the duration of the overlay.

Does anyone have any ideas on how I could achieve this? Thanks in advance! :)

share|improve this question
2  
One idea is to chain a fade filter to an overlay, but I haven't tried it so I don't know if it will work as expected. –  LordNeckbeard Nov 21 '12 at 20:38
    
@LordNeckbeard I'm willing to try it. How exactly would I do this? :) –  Miguel Nov 21 '12 at 21:41
    
I'm not sure, and I am unable to try it myself now. Asking at the ffmpeg-user mailing list may provide an answer. Make sure you're using a recent ffmpeg build. –  LordNeckbeard Nov 22 '12 at 4:20

1 Answer 1

Fade and Overlay

You can chain a fade and overlay filter together like so:

ffmpeg -i input.mp4 -f image2 -loop 1 -r 24 -i banner.png -filter_complex \
'[1:v]fade=out:96:24:alpha=1[wm];[0:v][wm]overlay=10:10[outv]' \
-map [outv] -map 0:a -c:a copy -c:v libx264 -preset veryfast output.mp4

-f image2 -loop 1 -r 24 -i banner.png turns banner.png into a 24fps video, looping to infinity.

[1:v]fade=out:96:24:alpha=1[wm] makes the watermark begin fading out at the 96th frame (4 seconds @ 24fps), and fade out over 24 frames (1 second @ 24fps); and it will fade out the alpha channel, meaning the watermark will turn transparent rather than fading to a black block. This creates an output labelled [wm]. Note that the lowest you can go for the length of the fade is 1 frame.

[0:v][wm]overlay=0:0[outv] overlays the banner on input.mp4, creating an output labelled [outv].

-map [outv] -map 0:a tells ffmpeg to use [outv] and the audio from input.mp4 in the output. The rest of the options are encoding options.

You can make the banner fade in and out by chaining two fade filters. The following will make the banner fade in starting at frame 96, with a duration of 24 frames; and then fade out starting at frame 216 (9 seconds @ 24fps), for a duration of 24 frames:

ffmpeg -i input.mp4 -f image2 -loop 1 -r 24 -i banner.png -filter_complex \
'[1:v]fade=in:96:24:alpha=1,fade=out:216:24:alpha=1[wm];[0:v][wm]overlay=10:10[outv]' \
-map [outv] -map 0:a -c:a copy -c:v libx264 -preset veryfast output.mp4

Stream Seeking with -ss and -t

This achieves a similar end-result, but requires the creation of larger intermediate files. However, it only transcodes the first five-second section, and so will save on processing power and possibly be faster.

This involves cutting the video into two bits using -t and -ss, putting the watermark over the first, five-second video, and then concatenating the two videos together.

ffmpeg -i input.mp4 -i watermark.png \
-filter_complex '[0:v][1:v]overlay[outv]' -map [outv] -map 0:a \
-t 5 -c:a copy -c:v libx264 -crf 22 -preset veryfast start.mp4

ffmpeg -i input.mp4 -ss 5 -c copy end.mp4

Then concatenate the two videos using the concat demuxer: first create a file called inputs.txt, containing the following lines:

file 'start.mp4'
file 'end.mp4'

Then,

ffmpeg -f concat -i inputs.txt -c copy output.mp4
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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