Search code examples
image-processingffmpegoverlaylibav

Overlaying alpha images on a video using ffmpeg


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)

Solution

  • 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