Search code examples
videoffmpeg

FFMPEG ignores "-shortest"


I'm using FFMPEG to overlay one video on another. It works, but the "-shortest" instruction is ignored.

This is the code:

ffmpeg -i "D:\Underlay.avi" -i "D:\Overlay.avi" -filter_complex \
[1:v]colorkey=0xFFFFFF:0.01:0.0[KeyedOverlay];\
[0:v][KeyedOverlay]overlay[Composite] \
-map [Composite] -c:v png -shortest "D:\Composite.avi"

Am I doing anything wrong? Is there an alternative method?


Solution

  • Both videos are being combined into a single video. Your output only has one video stream, so -shortest does nothing because it has no other streams to compare duration.

    Use the overlay specific shortest option instead:

    ffmpeg -i "D:\Underlay.avi" -i "D:\Overlay.avi" -filter_complex "[1:v]colorkey=0xFFFFFF:0.01:0.0[KeyedOverlay];[0:v][KeyedOverlay]overlay=shortest=1:format=auto[Composite]" -map "[Composite]" -c:v png "D:\Composite.avi"
    

    I also added format=auto so your overlay may look better.