Perelan
Perelan

Reputation: 406

Change video codec from VP8 to VP9 with native webRTC

I'm trying to figure out how to change the video codec on webRTC from vp8 to vp9, and do not find a suiting answer to this anywhere. May someone lead/show me how its done? Thanks

Upvotes: 4

Views: 4607

Answers (2)

TheoretiCAL
TheoretiCAL

Reputation: 20571

As browsers start to support setCodecPreferences, you can check for the mimetype of the codec you want to use by default to set the codec preference. For example if you want to prefer vp8 for video you can check for the "video/vp8" mimetype and set your codec preferences to vp8 codecs:

// 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);
}

Code adapted from this Pericror blog post to force audio/video codecs.

Upvotes: 0

Lasse Lumiaho
Lasse Lumiaho

Reputation: 66

I think you would need to munge SDP to make it happen. To my understanding the idea is that the endpoints negotiate the best possible codecs to be used.

The VP9 release news has some hints on how to change the preferred codec from VP8 to VP9 https://developers.google.com/web/updates/2016/01/vp9-webrtc?hl=en.

Upvotes: 5

Related Questions