Thursday, October 6, 2022

[SOLVED] How to merge 4 transparent videos so they stack together

Issue

I have 4 transparent videos with the same size, and the duration is just four seconds. They are all in webm format. I want to combine these 4 webm videos.

I used terminal command:

ffmpeg -c:v libvpx-vp9 -i 1.webm -c:v libvpx-vp9 -i 2.webm -filter_complex overlay aa.webm
ffmpeg -c:v libvpx-vp9 -i 3.webm -c:v libvpx-vp9 -i 4.webm -filter_complex overlay bb.webm
ffmpeg -c:v libvpx-vp9 -i aa.webm -c:v libvpx-vp9 -i bb.webm -filter_complex overlay output.webm

Is there a solution here that can be solved in one sentence? A simpler solution that would stack these four videos for 4 seconds and maintain transparency?


Solution

The solution is relatively straightforward:

ffmpeg -c:v libvpx-vp9 -i 1.webm -c:v libvpx-vp9 -i 2.webm -c:v libvpx-vp9 -i 3.webm -c:v libvpx-vp9 -i 4.webm -filter_complex "[0:v][1:v]overlay[aa];[2:v][3:v]overlay[bb];[aa][bb]overlay" -c:v libvpx-vp9 output.webm


  • Overlay 1.webm and 2.webm to [aa] (temporary name).

     [0:v][1:v]overlay[aa]
    
  • Overlay 3.webm and 4.webm to [bb] (temporary name).

     [2:v][3:v]overlay[bb]
    
  • Overlay [aa] and [bb]:

     [aa][bb]overlay
    


Answered By - Rotem
Answer Checked By - Mary Flores (WPSolving Volunteer)