问题
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