1

The (batch) script below produces a mosaic of the nine input videos:

FFMPEG ^
  -y  -i "v1.mp4" -i "v2.mp4" -i "v3.mp4" -i "v4.mp4" -i "v5.mp4" -i "v6.mp4" -i "v7.mp4" -i "v8.mp4" -i "v9.mp4" ^
  -filter_complex "[0:v][1:v][2:v]hstack=3[Row0];[3:v][4:v][5:v]hstack=3[Row1];[6:v][7:v][8:v]hstack=3[Row2];[Row0][Row1][Row2]vstack=3[v]" ^
  -map "[v]" -shortest "Mosaic3x3.mp4"  

The input videos are all 1280x720 and the resulting output is therefore 3840x2160 and takes a long time to render. The plan is to use this script as a basis to produce even larger mosaics and the time to render the output will become excessive.

So I wish to know the following:

is it preferable to scale the input videos before stacking them, or to scale the mega-sized mosaic output? Or both (scale at input and output)? I'm interested to know the trade-offs between scaling and output quality and processing time:

For a 6x6 mosaic, assuming a final resolution of 1920x1080, if I were to scale at the input, I would be scaling 1280x720 down to 320x180. I can't work out the command syntax for applying scaling at either end.

1 Answer 1

3

It is somewhat better to scale N mid-sized videos and then stack them rather than to stack N larger videos into a very large canvas and then scale it down.

ffmpeg ^
  -y  -i "v1.mp4" -i "v2.mp4" -i "v3.mp4" -i "v4.mp4" -i "v5.mp4" -i "v6.mp4" -i "v7.mp4" -i "v8.mp4" -i "v9.mp4" ^
  -filter_complex "[0:v]scale=320:180[v0];[1:v]scale=320:180[v1];[2:v]scale=320:180[v2];[3:v]scale=320:180[v3];[4:v]scale=320:180[v4];[5:v]scale=320:180[v5];[6:v]scale=320:180[v6];[7:v]scale=320:180[v7];[8:v]scale=320:180[v8];[v0][v1][v2]hstack=3[Row0];[v3][v4][v5]hstack=3[Row1];[v6][v7][v8]hstack=3[Row2];[Row0][Row1][Row2]vstack=3[v]" ^
  -map "[v]" -shortest "Mosaic3x3.mp4"  
1
  • Perfect, thanks. An order of magnitude faster for one thing, but your example also made things quite a bit clearer as to the syntax of the filter graphs.
    – rossmcm
    May 2, 2020 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .