目前H265应用越来越广泛,很多设备都支持硬件加速的H265编解码。作为最常见的音视频终端,Chrome在过去一直都没有H265支持的,毕竟不是AV1那样的亲儿子。人们为了让Chrome完整支持H265,用上了各种招式,例如传输上,用到了datachannel/WebTransport传输H265码流,解码上用到了wasm。
在Native端,要支持H265,得自己魔改WebRTC代码,例如第三方开源WebRTC库:Intel的OWT。现在这些状况就要改变了,目前Chrome已经支持H265硬解,WebRTC上也开始进行H265支持的开发,这一切都要从这个讨论开始:
Issue 41480904:Unblock Chrome platform support of H.265 (including H26xPacketBuffer),提到目前很多安防摄像机都是默认H265编码,修改为H264代价太高,大概率是国人提的需求😀。
目前WebRTC中H265代码由Intel团队的人提交,跟Intel自己的开源WebRTC库OWT中代码相似。目前代码中(截至2023.9.20)中主要三个提交,增加了H265 Nalu的解析,SDP中相关定义,RTP包处理/编解码器相关预留H265坑位,离实际能使用还有很多事情要做,如果感兴趣,也可以先看下Intel OWT中的H265代码,代码中搜索OWT_ENABLE_H265
字段,就可以看到H265相关。本文后续也将继续跟踪H265进展。
2025-03-12代码更新
Revert the deletion of WebRTC-VideoH26xPacketBuffer flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Revert the deletion of WebRTC-VideoH26xPacketBuffer flag. This unlaunches the experiment for H264 due to issues reported for H264 where the old packet buffer behaves better than the new one. A recently introduced issue will be fixed separately from this CL and rollout restarted. This CL is not a clean revert though (see delta with PS#1): we will continue to use the H26xPacketBuffer for the new codec H265 because it does not work with the old packet buffer anyway. Bug: webrtc:41480904 Change-Id: Icac49fa70f1c78d1ed596a7838d1417f6588a8b4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/380861 Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Jianlin Qiu <jianlin.qiu@intel.com> |
如上提交后,之前提到的Issue 41480904也被标记为fixed了,从2021到2025四年的跨度,WebRTC总算完成H265的支持。
根据提交代码可以知道,WebRTC-VideoH26xPacketBuffer
特性默认关闭的,接收到视频RTP包时,相关处理如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
bool RtpVideoStreamReceiver2::OnReceivedPayloadData() { // 对于H265,默认启用H26xPacketBuffer处理,只有WebRTC-VideoH26xPacketBuffer特性 // 开启,才会使用H26xPacketBuffer处理H264,这是因为对于H264,H26xPacketBuffer // 处理表现不如旧的PacketBuffer处理 if (h26x_packet_buffer_ && UseH26xPacketBuffer(packet->codec())) { OnInsertedPacket(h26x_packet_buffer_->InsertPacket(std::move(packet))); } else { OnInsertedPacket(packet_buffer_.InsertPacket(std::move(packet))); } } bool RtpVideoStreamReceiver2::UseH26xPacketBuffer( std::optional<VideoCodecType> codec) const { if (codec == kVideoCodecH265) { return true; } if (codec == kVideoCodecH264) { return env_.field_trials().IsEnabled("WebRTC-Video-H26xPacketBuffer"); } return false; } |
文章评论
太迫切了,希望 webrtc 能尽快支持 h265。chrome 支持 265 硬解之后,我司目前正在做的方案是 datachannel 传输裸流,客户端用 webcodes 进行解码,webgl 渲染。
我看代码m118已经支持了,通过rtc_use_h265 = proprietary_codecs 开启,默认浏览器应该也已经支持了把
@Jeffrey 目前支持情况还是我文中说的,H265的码流解析以及RTP包处理,具体你可以看下这个:https://source.chromium.org/search?q=rtc_use_h265&ss=chromium%2Fchromium%2Fsrc
Intel自己的开源WebRTC库OWT,是已经完整支持了H265么
@默 是的
Chrome从127版本开始支持WebRTC H265解码,但还只是实验性质的,启动参数需要添加 --enable-features=WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled
正式支持越来越近了。
24年了, webrtc现在支持了h265的rtp传输了吗?
@zzz 同问
@huowa222 2025-03-12的提交已经支持了