13

I'm trying to add overlays to an input video with ffmpeg that appear some time after the video starts.

The basic way to add an overlay is:

ffmpeg -i in.avi -vf "movie=overlay.avi [ovl]; [in][ovl] overlay" out.avi

But this adds the overlay video (or image) from the start of the input video until one of the videos ends.

I know how to offset the overlay video using movie=overlay.avi:seek_point=1.4, but what about an offset on the input video?

I could always clip the video to the desired point, add overlay on the second clip, then stitch the two but that's not very efficient.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
Future Optical
  • 201
  • 1
  • 2
  • 6

2 Answers2

13

Expanding on arttronics' insightful, but speculative answer, video can indeed be easily be overlaid offset using the -itsoffset flag.

The -itsoffset flag works like so:

-itsoffset offset (input)

Set the input time offset in seconds. [-]hh:mm:ss[.xxx] syntax is also supported. The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by offset seconds.

(NB: Despite the phrase "input files", the flag actually applies only to the input immediately following it. Note also this bug about offsets not applying to audio streams. H/T attronics.)

So overlaying with an offset is as simple as:

ffmpeg -i bg.avi -itsoffset 2 -i over.avi -filter_complex overlay out.avi

This works regardless of the container type.

Community
  • 1
  • 1
blahdiblah
  • 33,069
  • 21
  • 98
  • 152
  • **-1** The use of `-itsoffset` will apply the offset to **BOTH** files, not just the `overlay.avi` file. Reference [**ffmpeg Ticket 1349 itsoffset doesn't work for second input file**](http://ffmpeg.org/trac/ffmpeg/ticket/1349). Furthermore, the excerpt you posted confirms it's both **files**: ***the timestamps of the input files*** – arttronics Aug 04 '12 at 09:41
  • @attronics No, that's wrong. The docs are poorly written, but that bug ticket you mention is only for audio streams, and, more importantly, **this works**. Running the given command with current builds of FFmpeg has exactly the desired effect of delaying the overlay. – blahdiblah Aug 04 '12 at 17:48
  • Please revise your answer to include the docs are misleading, e.g. edit, so I can then Upvote. Thanks for clarifying. Cheers! – arttronics Aug 05 '12 at 01:14
8

According to the limited FFmpeg overlay documentation, the process expects that both videos have the same timestamp (e.g., 0:00:00:00) value to keep things in sync, and warns if not done then the avi.out will have an unwanted offset from the overlay.avi video file used.

However, you can use that that fact and take advantage of it!

It's then conceivable that if the overlay.avi video has a starting timestamp with the desired offset which is required on the in.avi input video, then the overlay.avi video will fire at that same timestamp (provided by in.avi) to create the expected outcome for the out.avi video.

The only bad news is the .avi container doesn't have timestamps, unlike .mp4 or .mkv file formats that do. You will have to switch to a file format that supports *timestamps* for this to work (e.g., overlay.mp4 or overlay.mkv) for creating the final output video file required.

arttronics
  • 9,957
  • 2
  • 26
  • 62