简体   繁体   English

ffmpeg 为 HTML MediaSource 流编码 mp4

[英]ffmpeg encode mp4 for HTML MediaSource stream

I've used this example to try and "stream" an mp4 video with multiple parts using MediaSource.我已经使用此示例尝试使用 MediaSource 来“流式传输”具有多个部分的 mp4 视频。 The files shouldnt be larger than 20mb due to host upload restrictions.由于主机上传限制,文件不应大于 20mb。

However I'm having trouble finding the correct encoder settings for it to work.但是,我无法找到使其工作的正确编码器设置。 The example files work fine if I use them on my code but everything I encode or "split" myself doesnt work.如果我在我的代码中使用它们,示例文件可以正常工作,但是我自己编码或“拆分”的所有内容都不起作用。

Here is the metadata (ffmpeg -i) of the files:这是文件的元数据 (ffmpeg -i):

file I want to encode:我要编码的文件:

Metadata:
major_brand     : mp42
minor_version   : 19529854
compatible_brands: mp42isom
creation_time   : 2017-01-23T17:09:58.000000Z
Duration: 00:04:46.65, start: 0.000000, bitrate: 3033 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
  creation_time   : 2017-01-23T17:09:58.000000Z
  handler_name    : Sound Media Handler
Stream #0:1(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 1920x1080 [SAR 1:1 DAR 16:9], 2836 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
  creation_time   : 2017-01-23T17:09:58.000000Z
  handler_name    : Video Media Handler
  encoder         : AVC Coding

One of the working files (the format I need):工作文件之一(我需要的格式):

Metadata:
major_brand     : mp42
minor_version   : 1
compatible_brands: mp42avc1iso5
Duration: 00:01:00.19, start: 0.000000, bitrate: 734 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 65 kb/s (default)
Metadata:
  handler_name    : Bento4 Sound Handler
Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360, 612 kb/s, 23.96 fps, 24 tbr, 600 tbn, 1200 tbc (default)
Metadata:
  handler_name    : Bento4 Video Handler
Stream #0:2(eng): Data: none (rtp  / 0x20707472), 45 kb/s (default)
Metadata:
  handler_name    : Bento4 Hint Handler
Stream #0:3(eng): Data: none (rtp  / 0x20707472), 5 kb/s (default)
Metadata:
  handler_name    : Bento4 Hint Handler

One of the commands I tried to use:我尝试使用的命令之一:

ffmpeg -i inputvid.mp4 -vcodec libx264 -acodec aac -pix_fmt yuv420p -profile:v baseline -level 3 testvid.mp4

Also to split the file into multiple part Ive been using "mp4box" so far:还要将文件分成多个部分,到目前为止我一直在使用“mp4box”:

mp4box -splits 19000 testvid.mp4

What would be the appropiate arguments for the encoding I need?我需要的编码的适当参数是什么?

And is mp4box for splitting ok or can i use ffmpeg for that aswell? mp4box 是否可以用于拆分,或者我也可以使用 ffmpeg 吗?

Thanks in advance!提前致谢!

Using chrome://media-internals/ I was able to figure out the required encoding which is apparently ISO BMFF.使用 chrome://media-internals/ 我能够找出显然是 ISO BMFF 所需的编码。

After some more research I came up with this working command for encoding:经过更多研究,我想出了这个用于编码的工作命令:

ffmpeg -i .input.mp4 -vcodec libx264 -acodec aac -pix_fmt yuv420p -movflags empty_moov+default_base_moof+frag_keyframe -profile:v baseline output.mp4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM