Video grid with vstack and hstack

I want to merge four videos into a grid. I am currently using vstack to merge strings, and then hstack to merge two outputs, and also to add sound.

 ffmpeg -ss 0 -i 1.mp4 -ss 8 -i 3.mp4 -filter_complex vstack left.mp4 ffmpeg -ss 0 -i 2.mp4 -ss 0 -i 4.mp4 -filter_complex vstack right.mp4 ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack -i audio.mp4 output.mp4 

This allows you to do this in one operation using overlay and pad . However, the documentation states that using vstack and hstack is faster. Can these two filters be combined in one operation?

+5
source share
1 answer

enter image description here

You can do it all in one command using hstack and vstack .

 ffmpeg -i top_l.mp4 -i top_r.mp4 -i bottom_l.mp4 -i bottom_r.mp4 -i audio.mp4 \ -filter_complex "[0:v][1:v]hstack[t];[2:v][3:v]hstack[b];[t][b]vstack[v]" \ -map "[v]" -map 4:a -c:a copy -shortest output.mp4 
  • Audio will stream copy from audio.mp4 instead of being re-encoded.

If you want the audio from each input to be combined instead of a separate audio input, use the amerge filter. -ac 2 added to the down-mix in stereo; otherwise, the output will have a cumulative number of audio channels.

 ffmpeg -i top_l.mp4 -i top_r.mp4 -i bottom_l.mp4 -i bottom_r.mp4 -filter_complex \ "[0:v][1:v]hstack[t];[2:v][3:v]hstack[b];[t][b]vstack[v]; \ [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" \ -map "[v]" -map "[a]" -ac 2 -shortest output.mp4 
+10
source

Source: https://habr.com/ru/post/1245931/


All Articles