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

支持webcodes吗? #16

Closed lishulincug closed 1 year ago

lishulincug commented 2 years ago

image 用chromium的 perf_tests/webcodecs里面的例子测了下,不行呀。 image

StaZhu commented 2 years ago

我这里试了下是没问题的,生成.hevc文件的方式: ffmpeg -f lavfi -i testsrc=size=1280x720:rate=1:duration=1 -pix_fmt yuv420p -vcodec hevc -tune zerolatency -f hevc 720p.hevc

代码: ` async function createDecodedFrame() { const config = {codec: 'hvc1.2.4.L93.B0', codedWidth: 1280, codedHeight: 720}; const result = await fetch('https://lf3-cdn-tos.bytegoofy.com/obj/tcs-client/resources/720p.hevc'); const buf = await result.arrayBuffer(); const chunk = new EncodedVideoChunk({timestamp: 0, type: 'key', data: buf});

let frame = null; const decoder = new VideoDecoder({ output: f => frame = f, error: e => console.log('Decode error:' + e) }); decoder.configure(config); decoder.decode(chunk); await decoder.flush(); return frame; } `

你可以再测试看看。

lishulincug commented 2 years ago

我这里试了下是没问题的,生成.hevc文件的方式: ffmpeg -f lavfi -i testsrc=size=1280x720:rate=1:duration=1 -pix_fmt yuv420p -vcodec hevc -tune zerolatency -f hevc 720p.hevc

代码: ` async function createDecodedFrame() { const config = {codec: 'hvc1.2.4.L93.B0', codedWidth: 1280, codedHeight: 720}; const result = await fetch('https://lf3-cdn-tos.bytegoofy.com/obj/tcs-client/resources/720p.hevc'); const buf = await result.arrayBuffer(); const chunk = new EncodedVideoChunk({timestamp: 0, type: 'key', data: buf});

let frame = null; const decoder = new VideoDecoder({ output: f => frame = f, error: e => console.log('Decode error:' + e) }); decoder.configure(config); decoder.decode(chunk); await decoder.flush(); return frame; } `

你可以再测试看看。

上面的数据是可以的,就是用自己的数据有点问题 image perf_tests_webcodecs.zip

StaZhu commented 2 years ago

emmm, 我刚才看了下代码,目前Chromium的VideoDecoder API确实还没实现HEVC,有时间我搞一下把。

StaZhu commented 2 years ago

你这边方便在crbug提个issue么?

lishulincug commented 2 years ago

crbug 在哪里?

StaZhu commented 2 years ago

https://crbug.com

lishulincug commented 2 years ago

提了https://bugs.chromium.org/p/chromium/issues/detail?id=1341201

StaZhu commented 2 years ago

我今天Debug了下这个问题,发现虽然VideoDecoder没加HEVC支持只是没加HEVC关键帧校验,但是并不影响解码,也就是说,问题关键在于你的用法。

Debug了下发现,你提供的.hevc如果直接拿来用,因为存在多个bitstream,但在解码这里认为是同一个Steam,但实际是多个,h265Decoder拿不到EOSStream,所以最后报错了。

至于现在Windows的h264能用,是因为h264解码不需要依靠之前的帧去parseSliceHeader,所以这块不会报错,然后下一步就是 FinishPrevFrameIfPresent,执行之后就会触发上一帧的解码,歪打正着。

但是这个用法是不对的,你可以试下macOS,直接按你写的,去解码H264也会直接失败。

lishulincug commented 2 years ago

想问下h265那个怎么写呢,这边读出来都在一个数据下了

StaZhu commented 1 year ago

w3c的hevc registration pr最近刚合进去,目前看前端侧确实可以掉到解码的能力,但是直接写因为缺少转换逻辑(原因是chrome内部对h264的description提取extradata做额外处理,不写description会报错,对265还没有这部分逻辑)会报错,所以可以认为chromium还不支持(edge也不支持,据我了解还没有浏览器支持),稍晚点我会在readme.md更新下支持情况,有新进展我也会在这个repo同步。issue先关了

taste1981 commented 1 year ago

@StaZhu Are you going to implement the hvcc to annex_b converter? I updated the WebCodecs testing page with HEVC support at: https://github.com/taste1981/taste1981.github.io/blob/main/webcodecs_decode/mp4-decode/mp4_demuxer.js If you're going to implement it, I will stop working on that :)

StaZhu commented 1 year ago

@StaZhu Are you going to implement the hvcc to annex_b converter? I updated the WebCodecs testing page with HEVC support at: https://github.com/taste1981/taste1981.github.io/blob/main/webcodecs_decode/mp4-decode/mp4_demuxer.js If you're going to implement it, I will stop working on that :)

Ah, surprising see you here~, I did read codes about this, but not currently working on this though. perhaps you may submit a crbug, and ask dan sanders if he is working on this actually :).

yisibl commented 1 year ago

@StaZhu 看起来Chrome 中 HEVC 的 WebCodecs 解码将在这里完成对吗? https://chromium-review.googlesource.com/c/chromium/src/+/3833477

HEVC 的 WebCodecs 编码有计划在实现了吗?

StaZhu commented 1 year ago

@StaZhu 看起来Chrome 中 HEVC 的 WebCodecs 解码将在这里完成对吗? https://chromium-review.googlesource.com/c/chromium/src/+/3833477

HEVC 的 WebCodecs 编码有计划在实现了吗?

WebCodec 实现 @taste1981 在搞了。编码计划不清楚,我个人没有计划实现。

lishulincug commented 1 year ago

这边利用最新的electron支持HEVC的WebCodecs ,只是Linux的好像还不行,win和mac的可以,需开启支持硬解。

StaZhu commented 1 year ago

@taste1981 Do you have plan to implement alpha layer HEVC video support for windows https://github.com/StaZhu/enable-chromium-hevc-hardware-decoding/issues/22

taste1981 commented 1 year ago

@StaZhu We don't have plan for this.

StaZhu commented 1 year ago

请今天下午再使用最新版Chrome Canary (107.0.5272.0) 测试一下吧 @taste1981 大佬给HEVC实现了webcodec支持🙏,感谢 (chrome基建问题,目前还不支持10bit及以上的视频)。

lishulincug commented 1 year ago

支持硬解码的。 https://intelligenttransportation.gitee.io/webcodes/rosbagPlayerWeb.html