Merge two videos with transparency in ffmpeg
16,087
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.
Related videos on Youtube
Author by
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
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
-
Titan over 7 yearsThis 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 over 7 yearscan you also explain the
top
andbottom
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 -
Janis S. over 6 years@Mulvya this works good, any way to repeat the shortest video?
-
Gyan over 6 yearsIf 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. -
Tomilov Anatoliy over 3 yearsHow to mix sound in addition to video? With above command audio channel from input #0 is used.