温馨提示:本文翻译自stackoverflow.com,查看原文请点击:video - FFmpeg splitting large files

video - FFmpeg分割大文件

发布于 2020-03-31 23:16:04

我需要将大型视频文件快速拆分成多个片段,并且没有错误的文件。基本思想是,我有一个2GB的视频文件,我想将其更改为多种格式。我已经读过一些编码器在编码为不同格式时不能使用多个内核。因此,我有一个主意,可以将大文件(非常快)分成4/8个部分,具体取决于我在单个服务器上可以使用多少个内核。将每个片段重新编码为新格式,并使用它们依次显示视频。

所以

testfile.mp4

变成

  1. testfile_piece_1.mp4
  2. testfile_piece_2.mp4
  3. testfile_piece_3.mp4
  4. testfile_piece_4.mp4

然后可以分别转换它们。

解决方案不应特定于格式。但是我发现mp4文件有问题。

我已经尝试了下面的命令,该命令确实非常好且快速,但是创建的文件带有错误。

ffmpeg -i testfile.mp4 -ss 00:00:00 -t 00:20:00 -c copy testfile_piece_1.mp4

当我在VLC上播放testfile_piece_1.mp4时,它可以正常工作。将拆分文件转换为不同高度和宽度的mp4文件时会出现问题。我将收到类似于“找不到Moov原子”的错误

我尝试添加-movflags faststart没有运气

然后,我遇到了这个库https://code.google.com/archive/p/moovrelocator/该库解决了moov问题,但是随后我会遇到关于aac的错误“打开输出流#0.0的编码器时出错-也许参数不正确,例如bit_rate,rate,width或height”

拆分文件的另一种方法是无用的,但需要重新编码文件。对于较小的文件大小来说还不错,但是2GB的文件可能需要几天才能完成。

有没有一种方法可以快速分割largr文件,而不会产生带有错误的文件?我已经为它工作了好几天,没有运气。

控制台输出以供注释-FFmpeg拆分大文件

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/share/nginx/html/uploads/testfile01.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.36.100
  Duration: 00:05:02.08, start: 302.120000, bitrate: 3254 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709)                                  , 1920x1080 [SAR 1:1 DAR 16:9], 3252 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (de                                  fault)
    Metadata:
      handler_name    : VideoHandler
[libx264 @ 0x165ffc0] width not divisible by 2 (853x480)
Output #0, mp4, to '/usr/share/nginx/html/uploads/testfile01_480.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.36.100
    Stream #0:0(und): Video: h264, none, q=2-31, 128 kb/s, SAR 2560:2559 DAR 0:0                                  , 25 fps (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc56.41.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters                                   such as bit_rate, rate, width or height

控制台输出2

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/share/nginx/html/uploads/testfile.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    creation_time   : 2016-01-24 04:26:37
  Duration: 01:15:58.08, start: 0.000000, bitrate: 3163 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 3161 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-01-24 04:26:37
      handler_name    : VideoHandler
[segment @ 0x1197060] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, segment, to '/usr/share/nginx/html/uploads/testfile%02d.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    encoder         : Lavf56.36.100
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 3161 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2016-01-24 04:26:37
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers

查看更多

提问者
Yusaf Khaliq
被浏览
36
Gyan 2016-02-01 23:01

使用段混合器将输入分成多个段:

ffmpeg -i testfile.mp4 -c copy -f segment -segment_time 1200 testfile_piece_%02d.mp4

这将在关键帧处分割源,因此片段的长度可能不完全是1200秒。而且时间戳不会重置,因此有些玩家将无法播放第二段和第二段。如果需要可玩性,请插入-reset_timestamps 1

并行编码后,您可以通过首先创建一个seg.txt像这样的文本文件来拼接生成的段

file 'encoded_testfile_piece_00.mp4'
file 'encoded_testfile_piece_01.mp4'
file 'encoded_testfile_piece_02.mp4'
file 'encoded_testfile_piece_03.mp4'

然后运行

ffmpeg -f concat -i seg.txt -c copy -fflags +genpts encoded_full.mp4

发布
问题

分享
好友

手机
浏览

扫码手机浏览