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

烈酒焚心 提交于 2019-12-13 19:05:39

问题


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


回答1:


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)


来源:https://stackoverflow.com/questions/51788193/webrtc-and-peerjs-how-to-choose-h264-instead-of-vp8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!