FFmpeg分割大文件 [英] FFmpeg splitting large files

查看:114
本文介绍了FFmpeg分割大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to split a large video file into multiple pieces quickly and without files with errors. The basic idea is, I have a 2GB video file which I want to change to multiple formats. I have read some encoders can not make use of more than 1 core when encoding to a different format. So I had the idea to split the large file (which is very quick) into 4/8 pieces depending on how many cores I have available on individual servers. re-encode each piece to a new format and use these to display video in sequence.

so

testfile .mp4

testfile.mp4

成为


  1. testfile_piece_1.mp4

  2. testfile_piece_2.mp4

  3. testfile_piece_3.mp4

  4. testfile_piece_4.mp4

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

然后可以单独转换这些。

these can then be individually be converted.

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

The solution should not be format specific. However I have found issues with mp4 files.

我尝试了下面的命令,该命令确实运行良好且速度很快,但是创建的文件带有错误。

I have tried the command below, which works really well and fast but creates files with errors.

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原子的错误

When I play the testfile_piece_1.mp4 on VLC it works fine. An issue arises when converting the split file to a different height and width mp4 file. I would get an error similar to "moov atom not found"

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

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

I then came across this library https://code.google.com/archive/p/moovrelocator/ which fixed the moov issue but I would then get an error with regards to aac "Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height"

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

The other way of splitting the files is useless but involved re-encoding the file. not too bad for smaller file size but the 2GB file would probably take days to complete.

有没有一种方法可以快速拆分largr文件而不会产生带有错误的文件?

Is there a way to split the largr file quickly without producing files with errors? I have been working on it for days with no luck.

控制台输出以进行评论- FFmpeg拆分大文件

Console output for comment - FFmpeg splitting large files

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


推荐答案

使用该段多路复用器将输入分成多个段:

Use the segment muxer to break the input into segments:

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

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

This will split the source at keyframes, so segments may not be exactly 1200 seconds long. And the timestamps aren't reset, so some players will fail to play the 2nd and latter segments. If playability is needed, insert -reset_timestamps 1.

并行编码后,可以通过以下方式拼接生成的段:首先创建一个文本文件 seg.txt

After the parallel encoding, you can stitch the generated segments by first creating a text file seg.txt like this

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

这篇关于FFmpeg分割大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆