I'm using ffmpeg to stitch together two videos of people chatting into a video with each of them side-by-side, like this:
Here's the command I'm currently using to get this done, which runs at ~2.5x on my 13" M1 MacBook Pro:
ffmpeg -y -i left.mp4 -i right.mp4 -filter_complex "
[0:v] crop=w=in_w/2 [croppedLeft];
[1:v][1:v] overlay=x=overlay_w/4 [shiftedRight];
[shiftedRight][croppedLeft] overlay [vout];
[0:a][1:a] amix [aout]
" -map "[vout]" -map "[aout]" -ac 2 out.mp4
This command crops the left video to half of its original width (cropping so the video is centered), then shifts the right video a quarter of its width to the right, then overlays the left video on the left half of the output merged with the shifted right video.
One day on my weekly fun-time read-through the FFmpeg filters documentation I stumbled on a filter named hstack
, which is described as being "faster than using overlay and pad filter to create same output."
My ex wife can affirm that there are few higher priorities in my life than going faster, so I altered my ffmpeg script to use hstack
instead of two overlay
s:
ffmpeg -y -i left.mp4 -i right.mp4 -filter_complex "
[0:v] crop=w=in_w/2 [croppedLeft];
[1:v] crop=w=in_w/2 [croppedRight];
[croppedLeft][croppedRight] vstack [vout];
[0:a][1:a] amix [aout]
" -map "[vout]" -map "[aout]" -ac 2 out.mp4
...but that command runs painfully slowly, like 0.1x. It takes multiple minutes to render a single second.
So uhhh what's going on here? Why is hstack taking so long when it's supposed to be faster?
I've tried this on both the M1 native build from OSXExperts (version N-99816-g3da35b7) and the standard ffmpeg from brew and hstack is just as slow on each.