webrtc和peerjs:如何选择H264而不是vp8? [英] webrtc and peerjs: how to choose H264 instead of vp8?

查看:443
本文介绍了webrtc和peerjs:如何选择H264而不是vp8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实使用peerjs https://peerjs.com 来稳定2个对等点之间的连接.

I do use peerjs https://peerjs.com to stablish connection between 2 peers.

有没有一种方法可以强制使用H264代码而不是VP8?

Is there a way to force the use of H264 code instead of VP8 ?

致谢

推荐答案

2020年3月更新: 现在,您可以使用 setCodecPreferences 来获得相同的结果,尽管只有新版本的浏览器才支持.

Update March 2020: You can now use setCodecPreferences to achieve the same result, though it's supported only on newer browser versions.

旧答案:

您将必须编辑peerjs代码才能更改编解码器.

You will have to edit the peerjs code to change codecs.

基本上,您将必须更新 SDP ,更具体地说,是更新sdp中的视频行

Basically you will have to update the SDP , more specifically, the video line in the sdp.

视频行将类似于

m=video 60372 UDP/TLS/RTP/SAVPF 96 98 100 101 116 111

数字100101等对应于对等方支持的各种编解码器,它们由如下所示的行表示:

The numbers 100 101 etc correspond to the various codecs that the peer support, they are represented by lines like the following:

a=rtpmap:98 VP9/90000
a=rtpmap:96 VP8/90000

因此,您必须首先获取sdp并找出H264编解码器的编号,然后将其移至视频行中列表的开头.

So you have to first get the sdp and find out the number for the H264 codec, next move the number to the beginning of the list in the video line.

例如,如果H264编解码器的编号为100,则需要将上述视频行更改为

For example, if 100 is the number of the H264 codec, you need to change the above video line to

m=video 60372 UDP/TLS/RTP/SAVPF 100 96 98 101 116 111

对于主叫方,在创建要约之后但在设置localDescription之前修改sdp

For the caller side, modify the sdp after creating the offer but before setting the localDescription

pc.createOffer().then(function(offer) {

    sdp = offer.sdp;
    changedsdp = updateCodec(sdp) //Function to modify the sdp
    offer.sdp = changedsdp

    pc.setLocalDescription(offer)

对于答录器端,在创建答案后修改sdp

For the answerer side, modify the sdp after create answer

pc.createAnswer(function(answer) {
    sdp = answer.sdp;
    changedsdp = updateCodec(sdp) //Function to modify the sdp
    answer.sdp = changedsdp
  pc.setLocalDescription(answer)

这篇关于webrtc和peerjs:如何选择H264而不是vp8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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