node-webrtc / node-webrtc-examples

MediaStream and RTCDataChannel examples using node-webrtc
508 stars 161 forks source link

Please help!! set preferred Codec to H264. #51

Open sagarvadodaria opened 1 year ago

sagarvadodaria commented 1 year ago

Guys, please help me with setting the preferred codec to H264.

offerSDP generated by 'doOffer' method in lib/server/connections/WebRTCConnection.js does not contain H264 at all. How can i enable the server to support H264 codec?

i tried below code to force preferred codec but get error. My server just needs to receive the video and save it as mp4. Thats why it is 'recvonly' as below. This is 'server.js' in 'record-audio-video-stream' example.

function beforeOffer(peerConnection) { 
const videoTransceiver = peerConnection.addTransceiver('video');     
  videoTransceiver.direction = "recvonly".   
   var codesc = [];   
   codesc.push({payloadType:106,mimeType:'video/H264', clockRate:90000});   
  videoTransceiver.setCodecPreferences(codesc)

Below is my offer sdp. (deleted all the candidate rows )

v=0 o=- 2540225252405802790 2 IN IP4 127.0.0.1 s=- t=0 0 a=group:BUNDLE 0 1 2 a=msid-semantic: WMS m=audio 64838 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 110 112 113 126 c=IN IP4 172.31.64.1 a=rtcp:9 IN IP4 0.0.0.0 a=ice-ufrag:tkt0 a=ice-pwd:RjFaXOd0NM1gJgt32XPE3qut a=fingerprint:sha-256 9F:41:EF:D7:93:B1:43:A8:44:3A:96:05:91:47:3B:A2:2D:8F:41:85:3A:95:5E:E8:08:11:2B:3B:33:DD:8A:C9 a=setup:actpass a=mid:0 a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id a=recvonly a=rtcp-mux a=rtpmap:111 opus/48000/2 a=rtcp-fb:111 transport-cc a=fmtp:111 minptime=10;useinbandfec=1 a=rtpmap:103 ISAC/16000 a=rtpmap:104 ISAC/32000 a=rtpmap:9 G722/8000 a=rtpmap:102 ILBC/8000 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:110 telephone-event/48000 a=rtpmap:112 telephone-event/32000 a=rtpmap:113 telephone-event/16000 a=rtpmap:126 telephone-event/8000 m=video 64844 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 124 125 c=IN IP4 172.31.64.1 a=rtcp:9 IN IP4 0.0.0.0 a=ice-ufrag:tkt0 a=ice-pwd:RjFaXOd0NM1gJgt32XPE3qut a=fingerprint:sha-256 9F:41:EF:D7:93:B1:43:A8:44:3A:96:05:91:47:3B:A2:2D:8F:41:85:3A:95:5E:E8:08:11:2B:3B:33:DD:8A:C9 a=setup:actpass a=mid:1 a=extmap:14 urn:ietf:params:rtp-hdrext:toffset a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time a=extmap:13 urn:3gpp:video-orientation a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 a=extmap:12 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing a=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07 a=extmap:9 http://www.webrtc.org/experiments/rtp-hdrext/color-space a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id a=recvonly a=rtcp-mux a=rtcp-rsize a=rtpmap:96 VP8/90000 a=rtcp-fb:96 goog-remb a=rtcp-fb:96 transport-cc a=rtcp-fb:96 ccm fir a=rtcp-fb:96 nack a=rtcp-fb:96 nack pli a=rtpmap:97 rtx/90000 a=fmtp:97 apt=96 a=rtpmap:98 VP9/90000 a=rtcp-fb:98 goog-remb a=rtcp-fb:98 transport-cc a=rtcp-fb:98 ccm fir a=rtcp-fb:98 nack a=rtcp-fb:98 nack pli a=fmtp:98 profile-id=0 a=rtpmap:99 rtx/90000 a=fmtp:99 apt=98 a=rtpmap:100 VP9/90000 a=rtcp-fb:100 goog-remb a=rtcp-fb:100 transport-cc a=rtcp-fb:100 ccm fir a=rtcp-fb:100 nack a=rtcp-fb:100 nack pli a=fmtp:100 profile-id=2 a=rtpmap:101 rtx/90000 a=fmtp:101 apt=100 a=rtpmap:127 red/90000 a=rtpmap:124 rtx/90000 a=fmtp:124 apt=127 a=rtpmap:125 ulpfec/90000 m=application 64850 UDP/DTLS/SCTP webrtc-datachannel c=IN IP4 172.31.64.1 a=ice-ufrag:tkt0 a=ice-pwd:RjFaXOd0NM1gJgt32XPE3qut a=fingerprint:sha-256 9F:41:EF:D7:93:B1:43:A8:44:3A:96:05:91:47:3B:A2:2D:8F:41:85:3A:95:5E:E8:08:11:2B:3B:33:DD:8A:C9 a=setup:actpass a=mid:2 a=sctp-port:5000 a=max-message-size:262144