1. ホーム
  2. ffmpeg

[解決済み] ffmpeg - 動画処理 - 空白の動画でトランジションを作成する

2022-02-14 18:02:38

質問

ffmpegの初心者が、簡単なはずのことに苦労しています。

3つの動画を連結して、そのうちの1つは空白の動画で2秒間のトランジションにしたいのですが、どうすればいいですか?

まず、空白の動画を生成します。

ffmpeg -f lavfi -i color=c=black:s=320x240:d=0.5 silent.mp4

手持ちの他の2つのビデオと連結してみたところ。

ffmpeg -i video-a.mp4 -i 2-seconds-silent-video.mp4 -i video-b.mp4 -y -filter_complex concat=n=3:v=1:a=1 result.mp4

手に入れたもの

ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libvpx --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-a.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:03.03, start: 0.033333, bitrate: 822 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 691 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2-seconds-silent-video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:02.00, start: 0.000000, bitrate: 17 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 11 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'video-b.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:03.03, start: 0.033333, bitrate: 745 kb/s
    Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 613 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Cannot find a matching stream for unlabeled input pad 5 on filter Parsed_concat_0

私も試したが成功しなかったもの。

ffmpeg -y -i "concat:video-a.mp4|2-seconds-silent-video.mp4|video-b.mp4" -c copy result.mp4

結果

ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libvpx --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd12a812800] Found duplicated MOOV Atom. Skipped it
    Last message repeated 1 times
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:video-a.mp4|2-seconds-silent-video.mp4|video-b.mp4':
  Metadata:
    encoder         : Lavf56.40.101
    minor_version   : 512
    major_brand     : isom
    compatible_brands: isomiso2avc1mp41
  Duration: 00:00:03.03, start: 0.033333, bitrate: 1579 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 691 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[mp4 @ 0x7fd12a033a00] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x7fd12a033a00] Codec for stream 1 does not use global headers but container format requires global headers
Output #0, mp4, to 'result.mp4':
  Metadata:
    compatible_brands: isomiso2avc1mp41
    minor_version   : 512
    major_brand     : isom
    encoder         : Lavf56.36.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 691 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=   75 fps=0.0 q=-1.0 Lsize=     305kB time=00:00:03.05 bitrate= 818.1kbits/s    
video:253kB audio:48kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.179313%

解決方法は?

空白のビデオを生成するときに、オーディオ・ストリームがありません。解決策は、動画に無音のオーディオストリームを追加することです。

ffmpeg -y -f lavfi -i anullsrc -i 2-seconds-silent-video.mp4 -shortest -c:v copy -c:a aac -strict experimental silent-video.mp4

は、@miindlekさんがここで答えてくれました、ありがとうございます。

上の行を見つけたところ。 ffmpegで無音音声を追加する