FFMPEG concat和/或MP4BOX的问题

时间:2016-11-11 05:54:38

标签: video ffmpeg mp4 h.264 mp4box

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

0 个答案:

没有答案