Overlay a watermark in avconv for a specific time

2019-07-16 04:03发布

问题:

How to overlay the picture label.gif only from second 1 to second 10? *enable=between(t,1,10)* didn't work

avconv -y -i input.mp4  -vf 'movie=label.gif [watermark]; 
[in][watermark] overlay=10:10 [out]' -c:v libx264 -crf 22 output.mp4

回答1:

The first thing that you will need to do is to generate the stream of video that consists of the single file. It is not enough to simply do -i file.jpeg, but you need to do -loop 1 -i file.jpeg (this will repeat the file indefinitely).

After that you can start applying different filters to that stream. The approach that i have done and tested on my computer is this:

avconv -i input.ogv -loop 1 -i logo.jpeg   -an \
  -filter_complex '[1:v]trim=start=1:end=2[ol]; [0:v][ol]overlay=eof_action=pass[final]' \
  -map '[final]' -c:v libtheora out3.ogv

Let's look at the command above and take it apart. As i have mentioned already -loop 1 generates an unending stream. Then we take that stream [1:v] and pass it through the trim filter with start and end parameters. The beauty of that filter is that it doesn't touch the timestamps, so although we have cut that stream to be 1 second long, it will still only start at second 1. There are other parameters for the trim filter, but since you were using between from ffmpeg my start and end will be obvious to you.

Then we can simply take that stream and use that in the overlay filter, but we should specify eof_action, since we don't want encoding to stop when the loop stream has ended. The pass action means that we will just continue with the original stream as if nothing has happened.