Posted: . At: 11:23 AM. This was 2 years ago. Post ID: 16170
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



How to use FFmpeg to merge multiple videos side by side.


Use FFmpeg to merge multiple videos in a collage

Merging multiple videos side by side is easy with FFmpeg. The FFmpeg example below will merge three videos together side by side. The resulting video will not end until the longest video clip ends.

1
2
3
4
5
6
7
8
9
#!/bin/bash
 
VID1="4rcq24.mp4"
VID2="fiajbh.mp4"
VID3="nsjl5e.mp4"
 
ffmpeg -i $VID1  -i VID2 -i $VID3 \
-filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih[1v][0v];[2:v][0v]scale2ref=oh*mdar:ih[2v][0v];[0v][1v][2v]hstack=3,scale='2*trunc(iw/2)':'2*trunc(ih/2)'"\
 final.mp4

This FFmpeg filter is what we use to do this, using the hstack=3 parameter to stack 3 videos side-by-side.

-filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih[1v][0v];[2:v][0v]scale2ref=oh*mdar:ih[2v][0v];[0v][1v][2v]hstack=3,scale='2*trunc(iw/2)':'2*trunc(ih/2)'"

Of course, this would work better if all 3 videos are the same length, but it still works well. If you could stack 6 videos on a video wall, that would be awesome, I am not sure if FFmpeg can even do something like that. But it would be nice to see it in action.

Just like this example.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Videos]
└─$ ffmpeg -i camps.mp4 -i camps.mp4 -i camps.mp4 -i camps.mp4 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]" -map "[v]" output.mp4

The example above will create a video wall using 4 videos as input. Make sure they are all the same length and this will work perfectly. A very cool FFmpeg trick to amaze your Youtube viewers. I used the same video 4 times, but this was just to test out the example and it works just fine. As long as all 4 videos are the same aspect ratio and the same length this will do it for you. The image below shows that this example really does work. This would look great if you had different video files that were on this video wall.

Using FFmpeg to create a video wall easily.
Using FFmpeg to create a video wall easily.

Another very useful FFmpeg tip.

https://securitronlinux.com/debian-testing/how-to-encode-a-movie-clip-with-ffmpeg-and-have-the-encoding-start-right-away/.

How to use FFmpeg to make a sound file louder.

https://securitronlinux.com/bejiitaswrath/how-to-increase-the-loudness-of-an-audio-track-using-ffmpeg-on-linux/.

Feed a Youtube video into FFmpeg directly with youtube-dl.

https://securitronlinux.com/bejiitaswrath/feed-a-youtube-video-into-ffmpeg-directly-with-youtube-dl/.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.