0

I have the following ffmpeg-cli command which does not produce the described effect in documentation. Could this be a bug, or I have something wrong with the command.

ffmpeg \
    -y \
    -i small.mp4 \
    -i monkey/monkey_%04d.png \
    -filter_complex "[0:v][1:v]overlay=enable='between(t,1,5)'[out1]" \
    -map '[out1]' \
    output.mp4

I expect it to overlay the #1 stream on top of #0 between seconds 1 and 5.

You may download the test tarball from this link:

It includes assets for the test case.

The build I tried with:

  • ffmpeg-3.0.2-64bit-static (available online)
neuro_sys
  • 805
  • 7
  • 13
  • Your image sequence is 21 frames, and with ffmpeg imputing a framerate of 25, the image stream ends before the overlay starts. How fast should the images go and should they loop? – Gyan May 10 '16 at 17:43
  • It's a test case, so they don't have to loop, and okay if finish earlier than specified in the enable option. Regardless, the output video does not have any overlay sequence, which is what I am concerned with presently. – neuro_sys May 10 '16 at 18:11

1 Answers1

4

FFmpeg is a time-based processor i.e. it aligns packets by timestamps, so you have to align the start of the image sequence to the start of the overlay.

ffmpeg \
    -y \
    -i small.mp4 \
    -i monkey/monkey_%04d.png \
    -filter_complex "[1:v]setpts=PTS-STARTPTS+(1/TB)[1v]; \
    [0:v][1v]overlay=enable='between(t,1,5)'[out1]" \
    -map '[out1]' \
    output.mp4
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Wow, thank you. Could you a bit elaborate on the filter that you used for further clarification? – neuro_sys May 10 '16 at 18:43
  • 1
    Sure. setpts generates new timestamps. The expression says to take the current relative timestamp `PTS-STARTPTS` and add 1 second to it. `TB` is the timebase unit i.e. the tick interval, which is the smallest time measuring unit for the video stream, so `3/TB` would represent an interval of 3 seconds. – Gyan May 10 '16 at 18:49
  • Oh, and would it be possible to specify exact frame numbers rather than seconds as timestamps (or millisecond precision at the least)? Because I have the frame numbers to overlay the image sequence rather than seconds (although I could easily conver them to milliseconds if necessary). – neuro_sys May 10 '16 at 18:51
  • No frames, but milliseconds, yes. – Gyan May 10 '16 at 18:52
  • 1
    Actually, frames is possible. `PTS-STARTPTS+(3/TB)+(11/FRAME_RATE*TB)` for a delay of 3s 11f – Gyan May 10 '16 at 18:54
  • Yes, however, enable=between(n, b, e) still works with seconds as far as I can tell. In which case I should better convert my frame numbers to seconds. – neuro_sys May 10 '16 at 19:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111566/discussion-between-neuro-sys-and-mulvya). – neuro_sys May 10 '16 at 19:07
  • 1
    No, n works with frame index, so (n,30,40) is between 30th and 40th frame processed by the filter. – Gyan May 10 '16 at 19:09