Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webrtc and peerjs: how to choose H264 instead of vp8?

Tags:

webrtc

peerjs

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

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

Regards

like image 272
yarek Avatar asked Dec 23 '22 05:12

yarek


1 Answers

Update: You can use setCodecPreferences to achieve the same result, once browsers support it.

Old Answer:

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

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

The video line will look something like

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

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

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.

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

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)

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)
like image 152
Akil Avatar answered Jan 04 '23 23:01

Akil