我如何(或有可能)将AVC编解码器配置文件和级别转换为MIME编解码器定义? [英] How can I (or is it possible to) convert the AVC codec profile and level to the MIME codec definition?

查看:150
本文介绍了我如何(或有可能)将AVC编解码器配置文件和级别转换为MIME编解码器定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的用例中,我必须在HTML5 视频 source 的MIME类型中提供编解码器规范.但是,即使 type ="video/mp4; codecs = avc1" 对于Firefox也不够详细.Firefox需要额外的细节,例如 type ="video/mp4; codecs = avc1.64001E" .我的问题是我不知道从何处获得此 64001E 部分.

In my use-case I have to provide codec specification within the HTML5 video source's MIME type. But even a type="video/mp4; codecs=avc1" is not detailed enough for Firefox. Firefox needs the extra detail of for example type="video/mp4; codecs=avc1.64001E". My problem is that I don't know where to get this 64001E part from.

整个标识发生在服务器端.到目前为止,我使用的是 ffprobe ,这完全可以为我提供JSON格式的输出,如下所示:

The whole identification happens on server side. So far I was using ffprobe and that's perfectly supplies me JSON format output, like so:

ffprobe -select_streams v:0 -v info -of json -show_entries stream=codec_name,level,profile,width,height -i 1CE89B23-F9BD-43B9-805B-C49ACA9E5FFB_xxxxxxx.mp4 
    "streams": [
        {
            "codec_name": "h264",
            "profile": "High",
            "width": 1080,
            "height": 1920,
            "level": 50
        }
    ]
}

我可以获得配置文件和级别,但是没有像 64001E 那样的东西.在我的本地环境中,我还有 mediainfo :

I can get the profile and the level, but nothing like 64001E. In my local environment I also have mediainfo:

mediainfo 8038B652-106B-4FBB-BAD6-AF7E32913FDE_xxxxxxx.mp4 
General
Complete name                            : 8038B652-106B-4FBB-BAD6-AF7E32913FDE_xxxxxxx.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 1.18 MiB
Duration                                 : 6 s 634 ms
Overall bit rate                         : 1 496 kb/s
Writing application                      : Lavf57.83.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3
Format settings                          : CABAC / 5 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 5 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 6 s 634 ms
Bit rate                                 : 1 396 kb/s
Width                                    : 360 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 0.750
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.269
Stream size                              : 1.10 MiB (93%)
Writing library                          : x264 core 152 r2854 e9a5903
Encoding settings                        : cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=8 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=15 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=50 / rc=crf / mbtree=1 / crf=17.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 6 s 632 ms
Duration_LastFrame                       : -9 ms
Bit rate mode                            : Constant
Bit rate                                 : 90.4 kb/s
Channel(s)                               : 1 channel
Channel layout                           : C
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 73.2 KiB (6%)
Default                                  : Yes
Alternate group                          : 1

我们在这里看到的是AAC部分具有更长的编解码器ID mp4a-40-2 ,但是视频流仍然只是 avc1 .

What we see here is that the AAC part has a longer Codec ID mp4a-40-2, but the video stream is still just avc1.

我正在查看列表 https://tools.woolyss.com/html5-canplaytype-tester/ https://wiki.whatwg.org/wiki/Video_type_parameters,我认为也许有一种编程方式可以将编解码器配置文件+级别转换为MIME类型编解码器规范所具有的代码.

I'm looking at lists https://tools.woolyss.com/html5-canplaytype-tester/ and https://wiki.whatwg.org/wiki/Video_type_parameters and I think maybe there's a programmatic way to convert the codec profile + level to the code what the MIME type codec specification has.

https://developer.mozilla.org/zh-CN/docs/Web/Media/Formats/codecs_parameter 我看到"avc1.4d002a" 表示 4.2级主配置文件.看一下我之前链接的列表,我发现可以将6个十六进制数字分解为两个一组.最后两个是级别.在此最新示例中,级别为 4.2 ,我们只需要删除点=>即可成为 42 ,即 2a 十六进制.其他4个十六进制数字与概要文件相关,例如Main,High等,然后是Progressive,但是我还没有找到定义,我想知道 ffprobe 是否能够输出高4:2:2帧内水平高进阶水平.我们会看到的.

In https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter I see that "avc1.4d002a" means Main Profile, Level 4.2. Looking at the list I linked earlier I figured that the 6 hex digits can be broken down into groups of two. The last two is the level. In this latest example the Level is 4.2, we just have to remove the dot => it becomes 42, which is 2a hex. The other 4 hex digits are related to the profile as Main, High, etc and then Progressive, but I haven't found a definition yet, and I wonder if the ffprobe is able to output things like High 4:2:2 Intra Level or High Progressive Level. We'll see.

https://tools.ietf.org/html/rfc6381#page-12有一些示例,但是我跟踪了链接,但仍然看不到任何确定的列表或任何内容.

https://tools.ietf.org/html/rfc6381#page-12 has some examples, but I followed the links and still don't see any definitive list or anything.

ITU-T H.264规范附件A列出了14个配置文件.在这些列表中,提到了 profile_idc ,它似乎是前两个十六进制数字的十进制数,例如 High profile_idc 是100十进制,即64六进制.现在我们只需要找出中间的两个十六进制数字即可.最好将这些内容整理成合理的简明const文字数组,然后将GitHub repo源文件打包.

The ITU-T H.264 specification Annex A lists 14 profiles. In those listings there's a profile_idc mentioned, which seems to be the decimal for the first two hex digits, for example High's profile_idc is 100 decimal, which is 64 hexa. Now we just need to figure out the middle two hexa digits. Preferably a GitHub repo source file would be great where these things are curated into a sane concise const literal array.

推荐答案

例如, Mozilla链接("PPCCLL为十六进制指定配置文件编号(PP),约束设置标志(CC)和级别(LL)的数字").如果找不到适合您需求的工具,我们可以扩展例如MediaInfo,让我们知道.
注意:列表中指示的CC是预期的标志,而不是文件中真正的标志,它在99.99%的时间内应该可以,但是您不能确保它是真实的内容.MediaInfo在内部读取这些标志,但暂时不导出它们.

It is described in e.g. Mozilla link ("PPCCLL is six hexadecimal digits specifying the profile number (PP), constraint set flags (CC), and level (LL)"). If you don't find a tool fitting your needs, we could extend e.g. MediaInfo for that, let us know.
Note: the CC indicated in the list are the expected flags, not the ones really in the file, it should be OK 99.99% of the time but you can not be sure it is the real content. MediaInfo internally reads the flags but it does not export them for the moment.

这篇关于我如何(或有可能)将AVC编解码器配置文件和级别转换为MIME编解码器定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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