1

I am using ffmpeg to create a composite video with multiple overlays onto a static background. I notice that ffmpeg creates a separate output stream in the output mp4 file for each overlay. Ideally, I would like these to be 'flattened' into a single stream. Is it possible to do this?

Here is simple example of what I mean - in this case I have a background 'logo' video onto which is being overlaid another video which is scaled to be a half the size of the background and is positioned in the top left corner of the output:

ffmpeg -i LOGO.mp4 -i VIDEO.mp4 
       -filter_complex "[1][0]scale2ref=iw/2:-2[scaled]; 
                        [0][scaled]overlay=x=0:y=0[composite]" 
       -map [composite] 
       -y OUTPUT.mp4

The resulting video has two video streams as shown by the output from ffmpeg:

Output #0, mp4, to 'OUTPUT.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
1

scale2ref consumes two inputs and then emits them both.. In your command, the output of the reference input isn't provided a label, nor connected elsewhere, nor fed to NULL output, so ffmpeg automatically maps it as output.

Use

ffmpeg -i LOGO.mp4 -i VIDEO.mp4 
       -filter_complex "[1][0]scale2ref=iw/2:-2[scaled][ref]; 
                        [ref][scaled]overlay=x=0:y=0[composite]" 
       -map [composite] 
       -y OUTPUT.mp4

The ref is now consumed by overlay and isn't left 'dangling' for ffmpeg to map.

As to your general query, just label the output of one overlay and feed it as the input to another, and you can combine them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.