大量の (>30) mp4 ファイルを連結する信頼できる方法を探していました。
これまでの私の方法は、MP4BOX concat CLI と FFMPEG の concat フィルター ( などffmpeg -auto_convert 1 -y -f concat -i files.txt -c copy out.mp4
) を試してきました。
どちらのツールでも同じ問題が発生します。2 つまたは 3 つのファイルを結合すると問題なく動作するようですが、それ以上の数のファイルを結合すると破損した mp4 ファイルが生成されます ( https://drive.google.com/file/d/0B_mWxBuwYcSgQjQtUnpQeUxVTm8/viewなど)。すべてのビデオが結合されるまで、一度に 2 つのビデオのみに結合する回避策を作成できますが、奇数の結合 (つまり 13) では機能しません。
これらのメソッドが一部のファイルでは機能するのに、他のファイルでは機能しないのはなぜですか?
FFPROBE は、これらの破損したファイルに対して予想されるエラーを生成します。
error while decoding MB x y, bytestream z
Reference 2 >= 2
top block unavailable for requested intra mode
FFMPEG 出力の例:
ffmpeg version N-80901-gfebc862 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.102 / 57. 0.102
libavfilter 6. 47.100 / 6. 47.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x36b3a80] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from 'twitter-files.txt':
Duration: N/A, start: 0.000000, bitrate: 415 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 284 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 130 kb/s
Metadata:
handler_name : SoundHandler
[mp4 @ 0x36b7dc0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Last message repeated 1 times
Output #0, mp4, to 'twitter-tmp.mp4':
Metadata:
encoder : Lavf57.41.100
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 284 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 130 kb/s
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3733160] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 1 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3733140] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x36b7dc0] Packet with invalid duration -512 in stream 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3733140] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 2 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x36ba960] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x36b7dc0] Packet with invalid duration -512 in stream 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x36ba960] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 4 times
[mp4 @ 0x36b7dc0] Non-monotonous DTS in output stream 0:0; previous: 306957, current: 306445; changing to 306958. This may result in incorrect timestamps in the output file.
[mp4 @ 0x36b7dc0] Non-monotonous DTS in output stream 0:0; previous: 306958, current: 306957; changing to 306959. This may result in incorrect timestamps in the output file.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x36ba960] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 1 times
frame= 750 fps=0.0 q=-1.0 Lsize= 1088kB time=00:00:30.04 bitrate= 296.6kbits/s speed= 366x
OSX 出力:
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.31)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --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-libxvid --enable-libvorbis --enable-libvpx --enable-vda
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49808c00] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from 'twitter-files.txt':
Duration: N/A, start: 0.000000, bitrate: 415 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 284 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 130 kb/s
Metadata:
handler_name : SoundHandler
Output #0, mp4, to 'tmp-twitter.mp4':
Metadata:
encoder : Lavf57.25.100
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 284 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 130 kb/s
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c4a005400] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c4a800000] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49800000] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x7f9c4a000c00] Packet with invalid duration -512 in stream 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49800000] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c4a800000] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 1 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49800000] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x7f9c4a000c00] Packet with invalid duration -512 in stream 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49800000] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c4a800000] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c4a005400] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c4a800e00] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49800000] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x7f9c4a000c00] Non-monotonous DTS in output stream 0:0; previous: 306957, current: 306445; changing to 306958. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7f9c4a000c00] Non-monotonous DTS in output stream 0:0; previous: 306958, current: 306957; changing to 306959. This may result in incorrect timestamps in the output file.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49800000] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9c49010e00] Auto-inserting h264_mp4toannexb bitstream filter
frame= 750 fps=0.0 q=-1.0 Lsize= 1146kB time=00:00:30.04 bitrate= 312.4kbits/s speed= 192x