问题描述
我一直在谷歌上搜索一种方法来更改 Chrome 的 WebRTC 实现中的编解码器,但似乎没有办法.
I've been googling a way to change codec in Chrome's implementation of WebRTC, but there doesn't seem to be a way.
如何更改 Chrome 中 WebRTCpeer 连接中使用的默认编解码器(音频或视频)?
How can I change the default codec used(audio or video) in a WebRTCpeer connection in Chrome?
推荐答案
是的,您可以将编解码器更改为您想要的任何内容……只要 Chrome 支持它.目前,在音频方面,唯一支持的编解码器是 PCMA、PCMU、ISAC 和 OPUS(默认).对于视频,您有 VP8(在某些带有 FireFox 的系统上也有 H264).
Yes, you can change the codec to be anything you want...as long as Chrome supports it. Right now, audio wise, the only supported codecs are PCMA, PCMU, ISAC, and OPUS(the default). For Video you have VP8(also H264 on some systems with FireFox).
要将这些编解码器中的任何一个用作默认值,您必须先修改您的 SDP,然后再在您的对等连接中本地设置它并发送您的提议/答案.我已经测试成功强制 Chrome 默认发送 PCMA 而不是 OPUS.
To use any of these codecs as default, you must modify your SDP before setting it locally in your peerconnection and sending your offer/answer. I have tested successfully forcing Chrome to send PCMA instead of OPUS by default.
举个例子:
假设您的默认音频 SDP 部分如下所示(括号中的注释不是 sdp 的一部分)
Say you have your default audio SDP section that looks like the following(notes are in brackets are are not part of the sdp)
m=audio<media> 49353<port> RTP/SAVPF<proto> 111 103 104 0 8 106 105 13 126 <rtpformats>
c=IN<nettype> IP4<addrtype> 192.168.0.13<address>
a=rtcp:49353<port> IN<nettype> IP4<addresstype> privateIP<connection address>
a=candidate:1204296370 1 udp 2122260223 privateIP 49353 typ host generation 0 <audioIceCandidate>
a=candidate:1204296370 2 udp 2122260223 privateIP 49353 typ host generation 0
a=candidate:155969090 1 tcp 1518280447 privateIP 0 typ host generation 0
a=candidate:155969090 2 tcp 1518280447 privateIP 0 typ host generation 0
a=ice-ufrag:E7VFzFythTIOaQ6X <ice username>
a=ice-pwd:ZMHFqqXEA8JLjItZcRN4FZDJ <ice-password>
a=ice-options:google-ice <iceoptions>
a=fingerprint:sha-256<encryptType> 66:2D:43:3A:31:7B:46:56:50:D7:CC:75:80:79:5D:88:7D:5D:1B:0E:C7:E6:F9:C4:68:6D:51:7F:4B:32:97:A1<print>
a=setup:actpass <dtls setup mode>
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level <extention map>
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=sendrecv <mediamode>
a=rtcp-mux <says rtcp mux>
a=rtpmap:111 opus/48000/2
a=fmtp:111 minptime=10
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:126 telephone-event/8000
a=maxptime:60
如果您只想使用 PCMA,您可以将 m=audio
行更改为以下内容:m=audio 49353 RTP/SAVPF 8
这样只考虑 PCMA 有效载荷.然后您需要删除所有与该有效负载不对应的 rtpmap 行,即下一个字符不是 8 的任何 a=rtpmap:
.如果您在本地设置修改后的 sdp 并将其发送到您的对等方(如果他们支持 PCMA...不必为他们默认,因为如果您只提供它,协商将强制使用 PCMA),那么 PCMA 将成为您的音频编解码器,而不是 OPUS.
If you wanted to ONLY use PCMA, you would change the m=audio
line to the following:m=audio 49353 RTP/SAVPF 8
this way only the PCMA payload is considered. Then you need to remove all the rtpmap lines that do not correspond with that payload, i.e. any a=rtpmap:
where the next character is NOT an 8. If you set that modified sdp locally and send it to your peer(and if they SUPPORT PCMA...does not have to be default for them as the negotiation will force PCMA if you only offer it), then PCMA will be your audio codec and not OPUS.
几个旁白:
- 我说的SDP是peerconnection的
createOffer
和createAnswer
函数的成功回调生成并传递过来的SDP - 这种类型的想法将适用于您知道底层系统(H264、SPEEX 等)支持的 ADDING 编解码器.只需确保添加有效负载以及适当的映射和选项(h264 需要
fmtp
,因为配置文件很重要,可能还有sprop-parameter-sets
). - 这适用于任何经过适当编码的 WebRTC 系统,例如 Firefox、Opera 等.而不仅仅是 chrome.
- The SDP I am talking about is the one generated and passed through the success callback of the
createOffer
andcreateAnswer
functions of the peerconnection - This type of idea will work for ADDING codecs that you know are supported by the underlaying systems(H264, SPEEX, etc.). Just make sure to add the payload and the appropriate mappings and options(
fmtp
is needed for h264 as profiles are important and possiblysprop-parameter-sets
). - This will work with any appropriately coded WebRTC system, i.e. Firefox, Opera, etc. Not just chrome.
这篇关于如何更改 WebRTC 中使用的默认编解码器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!