How to show overlay image in a certain time span with ffmpeg

7

3

I'm adding an overlay image to a video, which works, but I'd like to show it only in a certain time span:

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

This shows the error

key 'enable' not found

Sanket990

Posted 2014-02-07T05:23:33.593

Reputation: 171

Next time when asking questions about ffmpeg, please include the full, uncut command line output as well. – slhck – 2014-02-10T07:44:14.350

Answers

14

The syntax looks right to me. Use single quotes so you don't have to escape the expression:

ffmpeg -i input.mp4 -i watermark.png -filter_complex \
"[0:v][1:v] overlay=10:10:enable='between(t,1,2)'" output.mp4

If you don't have an enable option, make sure you use an ffmpeg version 2.0 or higher. Timeline editing is only supported there (see Changelog).

If you want multiple images overlaid, use something like this:

ffmpeg -i input.mp4 -i watermark.png -i watermark2.png -filter_complex \
"[0:v][1:v] overlay=10:10:enable='between(t,1,2)' [tmp]; [tmp][2:v] overlay=20:20:enable='between(t,2,3)'" output.mp4

slhck

Posted 2014-02-07T05:23:33.593

Reputation: 182 472

It's possible to not set time enable='between(t,2,3) but frames?? – zajca – 2015-03-10T09:30:30.150

@zajca Yes, use n instead of t. – slhck – 2015-03-10T10:26:37.447

The commands works perfectly but the issue is that when used with potrat videos , the merged video is rotated as landscape,can any help me understand why is it doing that . – PravinDodia – 2017-02-15T22:44:32.003

@PravinDodia You can try setting the rotation flag on the output: http://stackoverflow.com/questions/15335073/can-i-set-rotation-field-for-a-video-stream-with-ffmpeg/15336581#15336581

– slhck – 2017-02-16T08:34:47.827

@slhck I did that but , after doing that the images are also rotating which should not, so its a mess, but I think the issue is the version of ffmpeg, which I have updated and will update you all with my results. – PravinDodia – 2017-02-16T19:02:48.047

@PravinDodia It's best to ask a new question and give us some sample images, the command you're using, and the full command line output. – slhck – 2017-02-16T19:18:14.497

Note that between is inclusive at the end thus it will display an extra frame: https://www.ffmpeg.org/ffmpeg-utils.html

– Aalex Gabi – 2020-01-31T17:23:05.480

Thanks for suggestion. Can you give me link for ffmpeg version 2.0 or higher. – Sanket990 – 2014-02-10T11:27:27.940

You can download any version from the ffmpeg homepage: http://ffmpeg.org/download.html — depends on how you use it on Android though. You might have to compile it from source.

– slhck – 2014-02-10T12:55:19.790

thank u but getting 1 error unable to find suitable format '[tmp];[tmp][2:v] overlay=20:20:enable='between(t,2,3)'" output.mp4 – Sanket990 – 2014-02-19T09:39:57.087

Ah, sorry, the newline has to be removed or escaped. Please check my update. – slhck – 2014-02-19T09:46:14.030

i m executing update command getting error - opening an output file:overlay=10:10:enable='between(t,1,2)'. No such filter '' – Sanket990 – 2014-02-19T10:05:49.180

thank u command is working actually command execution minor mistake – Sanket990 – 2014-02-19T11:42:07.807

If the command worked, I'd be happy for you to accept the answer by clicking the green checkmark next to it. – slhck – 2014-02-19T11:43:44.580

ya i m traying voted up but votedup require 15 reputation sry for that and Thankx for helping – Sanket990 – 2014-02-19T12:02:24.317

I know you cannot vote up yet, but you can always accept an answer — just click the ✓ next to the answer.

– slhck – 2014-02-19T12:37:36.287

How to mapping multiple overlay using single image -i watermark.png it's possible or not – Sanket990 – 2014-02-25T11:11:52.800

Same idea, you just have to specify the same input image in the filtergraph (e.g. [1:v]), or use the same input image twice. – slhck – 2014-02-25T11:22:04.207

ffmpeg -i input.mp4 -i watermark.png -i watermark2.png -filter_complex
"[0:v][1:v] overlay=10:10:enable='between(t,1,2)' [tmp]; [tmp][1:v] overlay=20:20:enable='between(t,2,3)'" output.mp4 am i right?
– Sanket990 – 2014-02-25T11:34:17.380

Something like this, yeah, but the second watermark input is not necessary here. – slhck – 2014-02-25T12:23:35.633

yes command is working thanks but more and more adding overlay getting error i am adding overlay >380 up then error – Sanket990 – 2014-02-25T12:49:37.117

If you're getting errors with a new command please ask a new question with the command you're using and the full, uncut output. I cannot guess what your error is. By >380 do you mean over 380 images? – slhck – 2014-02-25T12:56:20.557