小智 6
以下ffmpeg命令将完全符合提问者的要求:
ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -filter_complex \
'[0:v]pad=iw*2:ih*2:0:0[int2];[int2][1:v]overlay=0:H/2[int3];[int3][2:v]overlay=W/2:0[int4];[int4][3:v]overlay=W/2:H/2[out]' \
-map [out] -c:v libx264 -crf 23 -preset veryfast output.mp4
Run Code Online (Sandbox Code Playgroud)
首先,填充滤镜将第一个输入视频的大小加倍,将原始视频保留在左上角.然后,串行覆盖滤波器将其他输入放在由填充滤波器添加的黑色填充上.
如果视频具有不同的分辨率,则该命令需要进行一些修改.
我自己目前正在使用 GStreamer 进行类似的项目(讲座捕获)。您可能正在寻找videomixer元素。查看此示例:视频 4 路分屏 gstreamer 管道(脚本位于此处)。
GStreamer 在 Windows 上也能完美运行。如果您有兴趣,您可能想查看GStreamer WinBuilds。
示例
这是一个适用于 Windows 的基本脚本(它没有反斜杠,因为我使用来自 C 代码的gst_parse_launch调用来解析管道描述):
v0. ! queue
! decodebin
! ffmpegcolorspace
! videoscale
! video/x-raw-yuv,width=320,height=240
! videobox right=-320 bottom=-240
! ffmpegcolorspace
! vmix.sink_0
v1. ! queue
! decodebin
! ffmpegcolorspace
! videoscale
! video/x-raw-yuv,width=320,height=240
! videobox bottom=-240
! ffmpegcolorspace
! vmix.sink_1
v2. ! queue
! decodebin
! ffmpegcolorspace
! videoscale
! video/x-raw-yuv,width=320,height=240
! videobox right=-240
! ffmpegcolorspace
! vmix.sink_2
v3. ! queue
! decodebin
! ffmpegcolorspace
! videoscale
! video/x-raw-yuv,width=320,height=240
! ffmpegcolorspace
! vmix.sink_3
vmix. ! queue
! ffmpegcolorspace
! dshowvideosink
filesrc location="c:/test.mpg" name="v0"
filesrc location="c:/test.mpg" name="v1"
filesrc location="c:/test.mpg" name="v2"
filesrc location="c:/test.mpg" name="v3"
videomixer name=vmix
sink_0::xpos=0 sink_0::ypos=0 sink_0::zorder=0
sink_1::xpos=320 sink_1::ypos=0 sink_1::zorder=1
sink_2::xpos=0 sink_2::ypos=240 sink_2::zorder=2
sink_3::xpos=320 sink_3::ypos=240 sink_3::zorder=3
Run Code Online (Sandbox Code Playgroud)