FFmpeg: 144 (16x9) grid of random Limmy Vine videos


It would have been nice to complete this all in one FFmpeg command (building such a command is a relatively trivial 'for loop' affair¹) but the level of file IO made this impossible (for my setup at least). Perhaps with smaller file sizes and fewer videos, it would be less impractical.

# Some basic Bash/FFmpeg notes on the procedures involved: 

# Select random 144 videos from current folder ('sort -R' or 'shuf')
find ./ -name "*.mp4" | sort -R | head -n 144

# Generate 144 '-i' input text for FFmpeg (files being Bash function parameters)
echo '-i "${'{1..144}'}"'
# Or use 'eval' for run-time creation of FFmpeg command
eval "ffmpeg $(echo '-i "${'{1..144}'}"')"

# VIDEO - 10 separate FFmpeg instances

# Create 9 rows of 16 videos with 'hstack', then use these as input for 'vstack'
[0:v][1:v]...[15:v]hstack=16[row1];
[row1][row2]...[row9]vstack=9
# [n:v] Input sources can be omitted from stack filters if all '-i' files used

# AUDIO - 1 FFmpeg instance

# Mix 144 audio tracks into one output (truncate with ':duration=first' option)
amix=inputs=144

# If needed, normalise audio volume in two passes - first analyse audio
-af "volumedetect"
# Then increase volume based on 'max' value, such that 0dB not exceeded 
-af "volume=27dB"

# Mux video and audio into one file
ffmpeg -i video.file -i audio.file -map 0:0 -map 1:0 out.file

# Addendum: Some other thoughts in reflection: Perhaps piping the files to a FFmpeg instance with a 'grid' filter might simplify things, or loading the files, one by one, inside the filtergraph via 'movie=' might be worth investigating. 
¹ See related: https://oioiiooixiii.blogspot.com/2017/01/ffmpeg-generate-image-of-tiled-results.html
context: https://en.wikipedia.org/wiki/Limmy
source videos: https://vine.co/Limmy