10

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%)?

ffmpeg
    -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
2
  • 1
    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
    Commented Jan 13, 2016 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
    Commented Jan 13, 2016 at 19:04

1 Answer 1

14

Use

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.

5
  • 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
    Commented Oct 9, 2016 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
    Commented Oct 9, 2016 at 21:22
  • @Mulvya this works good, any way to repeat the shortest video?
    – Janis S.
    Commented Nov 29, 2017 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
    Commented Nov 30, 2017 at 4:42
  • How to mix sound in addition to video? With above command audio channel from input #0 is used. Commented Dec 4, 2020 at 9:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .