I have two videos merged into one file using below command. Unfortunately second video covers first video and it is not visible. How to make second video transparent (eg. 50%)?

    -i in1.mp4 -i in2.mp4
    -filter_complex "nullsrc=size=480x360 [base];
        [0:v] setpts=PTS-STARTPTS, scale=480x360 [top];
        [1:v] setpts=PTS-STARTPTS, scale=480x360 [bottom];
        [base][top] overlay=shortest=1 [temp];
        [temp][bottom] overlay=shortest=1"
    -acodec libvo_aacenc -vcodec libx264 out.pm4
  • Unrelated to your question, but libvo_aacenc is a crappy AAC encoder. Use -c:a aac instead. If ffmpeg provides an error mentioning that aac is experimental then upgrade your ffmpeg because aac is no longer experimental. – llogan Jan 13 '16 at 18:57
  • Do both inputs contain audio? If yes, how do you want to deal with the audio? With your command ffmpeg will choose audio from one input. You should always include the complete console output from your command when asking for ffmpeg help. – llogan Jan 13 '16 at 19:04


ffmpeg \
    -i in1.mp4 -i in2.mp4 \
    -filter_complex " \
        [0:v]setpts=PTS-STARTPTS, scale=480x360[top]; \
        [1:v]setpts=PTS-STARTPTS, scale=480x360, \
             format=yuva420p,colorchannelmixer=aa=0.5[bottom]; \
        [top][bottom]overlay=shortest=1" \
    -acodec libvo_aacenc -vcodec libx264 out.mp4

Set aa to the opacity value needed.

  • This almost works for me except the main video (in1.mp4) stops showing video after in2.mp4 has finished, however the audio from in1.mp4 does continue for the duration of the video, just the video is "paused" – Titan Oct 9 '16 at 21:19
  • can you also explain the top and bottom my overlay sits left aligned and I'd like it centered, even if I have to specify the number of pixels it needs to move over – Titan Oct 9 '16 at 21:22
  • @Mulvya this works good, any way to repeat the shortest video? – Janis S. Nov 29 '17 at 21:57
  • If you know which input is shortest, its filterchain should be scale=480x360,loop=-1:99999:0,setpts=PTS-STARTPTS. where 99999 is a number equal or greater than its frame count. – Gyan Nov 30 '17 at 4:42

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.