html5-video - 我如何(或是否可能)将 AVC 编解码器配置文件和级别转换为 MIME 编解码器定义?

标签 html5-video mp4 codec ffprobe mediainfo

在我的用例中,我必须在 HTML5 video source 的 MIME 类型中提供编解码器规范。但即使是 type="video/mp4; codecs=avc1" 对于 Firefox 来说也不够详细。 Firefox 需要额外的详细信息,例如 type="video/mp4; codecs=avc1.64001E"。我的问题是我不知道从哪里得到这个 64001E 部分。

整个识别过程发生在服务器端。到目前为止,我使用的是 ffprobe,它完美地为我提供了 JSON 格式的输出,如下所示:

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:

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

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


https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter我看到 "avc1.4d002a" 表示 Main Profile, Level 4.2。查看我之前链接的列表,我认为 6 个十六进制数字可以分成两个一组。最后两个是水平。在这个最新的示例中,Level 是 4.2,我们只需删除点 => 它就变成了 42,即 2a 十六进制。其他 4 个十六进制数字与配置文件相关,如 Main、High 等,然后是 Progressive,但我还没有找到定义,我想知道 ffprobe 是否能够输出类似 High 4:2:2 Intra LevelHigh Progressive Level。我们拭目以待。


https://www.rfc-editor.org/rfc/rfc6381#page-12有一些例子,但我点击了链接,但仍然没有看到任何明确的列表或任何东西。


ITU-T H.264 规范附件 A 列出了 14 个配置文件。在这些列表中,提到了一个 profile_idc,它似乎是前两个十六进制数字的小数,例如 Highprofile_idc 是 100十进制,即 64 十六进制。现在我们只需要找出中间的两个十六进制数字。最好是 GitHub 存储库源文件,其中这些东西被整理成一个理智简洁的 const 文字数组。

最佳答案

它在例如Mozilla link (“PPCCLL 是六个十六进制数字,指定配置文件编号 (PP)、约束集标志 (CC) 和级别 (LL)”)。如果您找不到适合您需求的工具,我们可以扩展例如MediaInfo,let us know .
注意:列表中指示的 CC 是预期的标志,而不是文件中真正的标志,99.99% 的时间应该没问题,但您不能确定它是真实的内容。 MediaInfo 在内部读取标志,但暂时不导出它们。

关于html5-video - 我如何(或是否可能)将 AVC 编解码器配置文件和级别转换为 MIME 编解码器定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59891176/

相关文章:

html - 检测 HTML 视频源更改事件 (addEventListener)

c++ - 从 C++ 系统调用时 ffmpeg 不起作用

video - 解压缩 MP4 文件中的 time-To-Sample 表 (STTS)

android - ffmpeg 命令将不同类型和分辨率的视频连接成 1 个视频并可以在 android 中播放

audio - OPUS文件代码,如何打开

ios - HTML5 Safari iOS 只能访问相机而不是照片库

javascript - 如何禁用 HTML 视频播放器播放速度/三个点

ios - iOS 上的 HTML5 自定义相机 View

iphone - 如何在 ios 中使用 AudioQueue 编码/解码 speex

MongoDB Scala 驱动程序 - 呈现 BSON 文档