FFMPEG XStack Audio Cuts out After Shortest Video

Viewed 83

I'm trying to combine 4 Video files from a CDN into a grid using FFMPEG and the xstack filter.

This is the command I'm running.

ffmpeg -y -i https://exampl.cdn.com/99d11c26-352d-4f29-ba83-38deeaf766d4.mp4 
-i https://exampl.cdn.com/99d11c26-352d-4f29-ba83-38deeaf766d4.mp4 
-i https://exampl.cdn.com/66581fbf-cfed-4de1-a634-f011b6792e9f.mp4 
-i https://exampl.cdn.com/a8f0d337-98cb-4067-b3e9-78dca8a82bcf.mp4
-filter_complex 
"xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[out];[0:a][1:a][2:a][3:a]amerge=inputs=4[a]"
-map "[out]"
-map "[a]"
-ac 2
output.mp4

The video generates just fine and the audio plays back, but the audio cuts out after the shortest video ends. The videos keep playing though. The videos are generated by end-users via the HTML video object and uploaded to S3.

1 Answers

Figured it out. I had to use the amix filter.

https://ffmpeg.org/ffmpeg-filters.html#amix

This is the final command I ended up with.

ffmpeg -y -i vid1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i vid-4.mp4 -filter_complex "xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0;amix=inputs=4" output.mp4
Related