StaZhu / enable-chromium-hevc-hardware-decoding

A guide that teach you enable hardware HEVC decoding & encoding for Chrome / Edge, or build a custom version of Chromium / Electron that supports hardware & software HEVC decoding and hardware HEVC encoding.
MIT License
1.15k stars 56 forks source link

chrome 119 版本后 h265解码失败 #61

Closed ashimidashajia closed 8 months ago

ashimidashajia commented 8 months ago

再次打扰您了! 前两天升级到 chrome 119 版本后,之前的代码突然解码h265失败了。再次回退到119之前的版本,如118版本,就可以正常解码。 119 之后,API接口有什么特殊变化吗? codec 配置如下: this._hevcDecoder.configure({ codec: "hev1.1.6.L150", codedWidth: this._imageWidth, codedHeight: this._imageHeight, optimizeForLatency: true, hardwareAcceleration: "prefer-hardware", }); 没有设置: image

StaZhu commented 8 months ago

没遇到过类似的问题。什么系统?什么GPU?chrome://gpu 有没有 Decode hevc main 字段?

ashimidashajia commented 8 months ago

windows/mac 都遇到了(Linux下未测试),chrome://gpu 有 Decode hevc main 字段。我们同样的代码,chrome 119 之前版本可以正常解码播放,但是119版本,就会报 “解码错误” 的日志。 另外,上周五chrome开始自动升级到119版本。

StaZhu commented 8 months ago

麻烦提供一下最小复现demo

ashimidashajia commented 8 months ago

samples.tar.gz 在 samples 文件夹中: python -m http.server 10000 在浏览器中: http://localhost:10000/video-decode-display/

chrome 118版本: image

chrome 119版本: image

mp4文件路径: data/test_h265.mp4

StaZhu commented 8 months ago

请问这个用的是Edge浏览器?

StaZhu commented 8 months ago

Edge 浏览器 117 版本之后就不支持 WebCodecs 解码 HEVC了,因为它切换的 MediaFoundation for Clear 方案不兼容 WebCodecs。

StaZhu commented 8 months ago

抱歉,我在 macOS 能复现,我看下为啥哈,我知道 M109 Parse VPS 加了一些东西,应该跟这个 CL 有关系:https://chromium-review.googlesource.com/c/chromium/src/+/4863237

要么就是这个视频的码流 VPS有问题,要么就是解析逻辑的问题。

StaZhu commented 8 months ago

看了下代码,发现是您提供的 Sample 视频的 VPS 码流有问题,在 Chrome 119 版本之前 Chrome 并不会解析 VPS extension 数据,在 Chrome 119 之后开始解析 VPS extension 暴露了问题。

Chrome 本身的解析逻辑没啥问题,你的视频 Sample 的 vps_extension_flag = 1,说明有 vps_extension, 但是在解析 vps_extension 数据不全, scalability_mask_flag 在读到第 8个 bit 时没数据了(正常应该要能读满16个bit),导致出错了。

出错的代码逻辑在这里:https://source.chromium.org/chromium/chromium/src/+/main:media/video/h265_parser.cc;l=427

请你看一下 HEVC Spec F.7.3.2.1.1,看看视频码流是否有问题。

ashimidashajia commented 8 months ago

非常感谢您的解答,我按照您的思路去分析下!

ashimidashajia commented 8 months ago

是我们码流的问题,非常感谢您的帮助!