同时添加 2 秒延迟并延迟 -ffmpeg- 中的输入之一

Simultaneously adding a 2-second delay and delaying one of the inputs in -ffmpeg-

我想在我的 multi-screen 电影 的开头添加两秒的静音空白,有效地提前了其中一个输入(视频和音频)的开始三秒,所有其他输入在此之后开始。

这是我正在尝试做的 3x3 网格示例:

ffmpeg -i r.mp4 -i s.mp4 -i t.mp4 -i u.mp4 -i v.mp4 -i w.mp4 -i x.mp4 -i y.mp4 -i z.mp4 -filter_complex "[0:v]scale=iw/5:-1[v0];[1:v]scale=iw/3:-1[v1];[2:v]scale=iw/3:-1[v2];[3:v]scale=iw/3:-1[v3];[4:v]scale=iw/3:-1[v4];[5:v]scale=iw/3:-1[v5];[6:v]scale=iw/3:-1[v6];[7:v]scale=iw/3:-1[v7];[8:v]scale=iw/3:-1[v8];[0:v]tpad=start_duration=3[v0];[1:v]tpad=start_duration=3[v1];[2:v]tpad=start_duration=3[v2];[3:v]tpad=start_duration=0[v3];[4:v]tpad=start_duration=3[v4];[5:v]tpad=start_duration=3[v5];[6:v]tpad=start_duration=3[v6];[7:v]tpad=start_duration=3[v7];[8:v]tpad=start_duration=3[v8];[1:a]adelay=3s:all=true[a1];[2:a]adelay=3s:all=true[a2];[3:a]adelay=3s:all=true[a3];[4:a]adelay=0s:all=true[a4];[5:a]adelay=3s:all=true[a5];[6:a]adelay=3s:all=true[a6];[7:a]adelay=3s:all=true[a7];[8:a]adelay=3s:all=true[a7];[8:a]adelay=3s:all=true[a8];[v0][v1][v2][v3][v4][v5][v6][v7][v8]xstack=inputs=9:layout=0_0|0_h0|0_h0+h1|w0_0|w0_h0|w0_h0+h1|w0+w4_0|w0+w4_h0|w0+w4_h0+h1;[0:a][1:a][2:a][3:a][4:a][5:a][6:a][7:a][8:a]amix=inputs=9" -vsync 2 output.mp4

结果输出为:

ffmpeg version 4.3.2-0+deb11u1ubuntu1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10 (Ubuntu 10.2.1-20ubuntu1)
  configuration: --prefix=/usr --extra-version=0+deb11u1ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0+deb11u1ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-liblensfun --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'r.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:08.00, start: 0.000000, bitrate: 248 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 41 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 193 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 's.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:10.00, start: 0.000000, bitrate: 480 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 271 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 194 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 't.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:09.00, start: 0.000000, bitrate: 256 kb/s
    Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 49 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 193 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'u.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:17.00, start: 0.000000, bitrate: 259 kb/s
    Stream #3:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 53 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #3:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 193 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'v.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:09.00, start: 0.000000, bitrate: 255 kb/s
    Stream #4:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 48 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #4:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #5, mov,mp4,m4a,3gp,3g2,mj2, from 'w.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:07.00, start: 0.000000, bitrate: 461 kb/s
    Stream #5:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 250 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #5:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #6, mov,mp4,m4a,3gp,3g2,mj2, from 'x.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 267 kb/s
    Stream #6:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 59 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #6:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 194 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #7, mov,mp4,m4a,3gp,3g2,mj2, from 'y.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:05.01, start: 0.000000, bitrate: 246 kb/s
    Stream #7:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 39 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #7:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #8, mov,mp4,m4a,3gp,3g2,mj2, from 'z.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:09.00, start: 0.000000, bitrate: 294 kb/s
    Stream #8:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 86 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #8:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 195 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
File 'output.mp4' already exists. Overwrite? [y/N] y
Filter adelay has an unconnected output

这(对我来说)很奇怪,因为我忠实地遵循了 Lou Logan 在标题为 Delaying/pausing 视频 here 部分下的示例,但我的代码仍然因错误而窒息。基本上,我无法清楚地看到哪个 adelay 调用(如果只有其中一个;可能全部九个)是 'unconnected' 以及为什么。

这里有什么解决办法?同样,这可能很明显!

非常感谢克莱夫

立即启动t.mp4,延迟其他人3秒的示例:

ffmpeg -i r.mp4 -i s.mp4 -i t.mp4 -i u.mp4 -i v.mp4 -i w.mp4 -i x.mp4 -i y.mp4 -i z.mp4 -filter_complex "[0:v]tpad=start_duration=3,scale=iw/5:-1[v0];[1:v]tpad=start_duration=3,scale=iw/5:-1[v1];[2:v]tpad=start_duration=3,scale=iw/5:-1[v2];[3:v]scale=iw/5:-1[v3];[4:v]tpad=start_duration=3,scale=iw/5:-1[v4];[5:v]tpad=start_duration=3,scale=iw/5:-1[v5];[6:v]tpad=start_duration=3,scale=iw/5:-1[v6];[7:v]tpad=start_duration=3,scale=iw/5:-1[v7];[8:v]tpad=start_duration=3,scale=iw/5:-1[v8];[0:a]adelay=3s:all=true[a0];[1:a]adelay=3s:all=true[a1];[2:a]adelay=3s:all=true[a2];[4:a]adelay=0s:all=true[a4];[5:a]adelay=3s:all=true[a5];[6:a]adelay=3s:all=true[a6];[7:a]adelay=3s:all=true[a7];[8:a]adelay=3s:all=true[a8];[v0][v1][v2][v3][v4][v5][v6][v7][v8]xstack=inputs=9:layout=0_0|0_h0|0_h0+h1|w0_0|w0_h0|w0_h0+h1|w0+w4_0|w0+w4_h0|w0+w4_h0+h1;[a0][a1][a2][3:a][a4][a5][a6][a7][a8]amix=inputs=9" output.mp4
  • 您的命令将 tpad 和 scale 输出到相同的 labels/names/“pads”,但它不起作用。将 tpad 和 scale 组合成单独的 filterchains.
  • 您的 amix 被告知使用 [0:a][1:a][2:a][3:a][4:a][5:a][6:a][7:a][8:a] 而不是 [a0][a1][a2][3:a][a4][a5][a6][a7][a8] 作为输入。因为 [a0][a1][a2][3:a][a4][a5][a6][a7][a8] 未被任何过滤器或输出使用,因此是孤立的和未连接的,所以您收到错误 Filter adelay has an unconnected output.
  • 您使用了 [a7] 延迟了 2 次。