1

我一直在寻找一种可靠的方法来连接大量 (>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  
4

0 回答 0