用原生webRTC将视频编解码器从VP8更改为VP9



我正试图弄清楚如何将视频编解码器从vp8更改为vp9,并且在任何地方都找不到合适的答案。有人能告诉我怎么做吗?由于

我认为你需要修改SDP来实现它。根据我的理解,这个想法是端点协商要使用的最佳编解码器。

VP9发布新闻有一些提示如何将首选编解码器从VP8更改为VP9 https://developers.google.com/web/updates/2016/01/vp9-webrtc?hl=en.

随着浏览器开始支持setCodecPreferences,您可以检查想要默认使用的编解码器的mime类型来设置编解码器首选项。例如,如果你想使用vp8视频,你可以查看"video/vp8"mime类型并将编解码器偏好设置为vp8编解码器:

// note the following should be called before before calling either RTCPeerConnection.createOffer() or createAnswer()
let tcvr = pc.getTransceivers()[0];
let codecs = RTCRtpReceiver.getCapabilities('video').codecs;
let vp8_codecs = [];
// iterate over supported codecs and pull out the codecs we want
for(let i = 0; i < codecs.length; i++)
{
   if(codecs[i].mimeType == "video/VP8")
   {
      vp8_codecs.push(codecs[i]);
   }
}
// currently not all browsers support setCodecPreferences
if(tcvr.setCodecPreferences != undefined)
{
   tcvr.setCodecPreferences(vp8_codecs);
}

改编自Pericror博客文章的代码,用于强制音频/视频编解码器

最新更新