ffmpeg-python
ffmpeg-python copied to clipboard
How can add mosaic or stacking?
Any recommendation what would be the best way to add capability to do a mosaic of 4 videos?
The orginial ffmpeg command would like this one
ffmpeg
-i input0.mp4 -i input1.mp4 -i input2.mp4 -i input3.mp4
-filter_complex
"[0:v][1:v]hstack=inputs=2[top];
[2:v][3:v]hstack=inputs=2[bottom];
[top][bottom]vstack=inputs=2[v]"
-map "[v]"
finalOutput.mp4
yes I would also like to know this. The existing examples are great. I just wish there were more of them
ffmpeg -i input0 -i input1 -i input2 -i input3 \
-filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]" \
-map "[v]" output
oooo I think I figured it out just by monkey-on-the-typewriter-ing it
import os
import ffmpeg
in0 = ffmpeg.input(os.path.expanduser("~/.tmp/2022_0412_090814_F.mp4"))
in1 = ffmpeg.input(os.path.expanduser("~/.tmp/2022_0412_090814_R.mp4"))
aout = ffmpeg.filter(
[
in0.audio,
in1.audio,
],
"amultiply",
)
vout = ffmpeg.filter(
[
in0.video,
in1.video,
in1.video,
in0.video,
],
"xstack",
inputs=4,
layout="0_0|w0_0|0_h0|w0_h0",
)
(
ffmpeg.output(
aout,
vout,
"out.mkv",
).run()
)
if someone makes more examples there should also be a multiple output streams example:
aout = [
in0.audio,
in1.audio,
]
(
ffmpeg.output(
vout,
in0.audio,
in1.audio,
"out.mkv"
).run()
)
it's confusing at first but then it makes sense !