title: WEBRTC Relay Video to Third Peer (Video is Black With H264)
body: <p>I'm working on a system where video can be relayed to additional peers with the goal of avoiding server costs. A video sender opens an RTCPeerConnection with someone who can then pipe it to someone else using an additional RTCPeerConnection. I've gotten this to work with the default SDP by adding the receiver tracks from peer two onto peer three. However, when I change the preferred codec by modifying the SDP the third peer shows a black video element. <code>chrome://webrtc-internals</code> reveals that the third peer is receiving data. Again, everything works fine if I leave the SDP alone but I want to use a different codec.</p>
  <p><strong>Pipe Tracks</strong></p>
  <pre class="lang-js prettyprint-override"><code>async function pipeTracks(source: RTCPeerConnection, destination: RTCPeerConnection): Promise&lt;void&gt; {
      await waitForPeerTracks(source) //Ensures there are video and audio receivers
      source.getReceivers().forEach(receiver =&gt; {
          destination.addTrack(receiver.track)
      })
  }
  </code></pre>
  <p><strong>Modify SDP</strong></p>
  <pre class="lang-js prettyprint-override"><code>async function createOffer(peer: RTCPeerConnection, options?: RTCOfferOptions): Promise&lt;RTCSessionDescription&gt; {
      let offer = await peer.createOffer(options)
      if(offer.sdp) {
          // 1. Find codec number
          // 2. put codec number to front of m=video line
      }
      let localDescription = new RTCSessionDescription(offer)
      await peer.setLocalDescription(localDescription)
      return localDescription
  }
  </code></pre>
  <p><strong>Peer 1 to Peer 2 Offer SDP</strong></p>
  <pre><code>v=0
  o=- 1032594076002778521 2 IN IP4 127.0.0.1
  s=-
  t=0 0
  a=msid-semantic:  WMS
  a=group:BUNDLE 0 1
  m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 110 112 113 126
  c=IN IP4 0.0.0.0
  a=rtpmap:111 opus/48000/2
  a=rtpmap:103 ISAC/16000
  a=rtpmap:104 ISAC/32000
  a=rtpmap:9 G722/8000
  a=rtpmap:0 PCMU/8000
  a=rtpmap:8 PCMA/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
  a=fmtp:111 minptime=10;useinbandfec=1
  a=rtcp:9 IN IP4 0.0.0.0
  a=rtcp-fb:111 transport-cc
  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=setup:actpass
  a=mid:0
  a=msid:- a9dfc3b2-bb66-4bdd-930a-cd6768c65122
  a=sendrecv
  a=ice-ufrag:ACjb
  a=ice-pwd:YSuamSFAtSftl3fFMK1DxZlB
  a=fingerprint:sha-256 79:F4:75:F0:F6:72:DF:B9:2C:2D:51:8A:7E:EA:29:73:27:3E:5A:21:0A:09:97:A9:0B:B9:AF:0C:83:0B:3B:0E
  a=ice-options:trickle
  a=ssrc:639037895 cname:Z4s5Y/IGpkZKjhS2
  a=ssrc:639037895 msid:- a9dfc3b2-bb66-4bdd-930a-cd6768c65122
  a=ssrc:639037895 mslabel:-
  a=ssrc:639037895 label:a9dfc3b2-bb66-4bdd-930a-cd6768c65122
  a=rtcp-mux
  m=video 9 UDP/TLS/RTP/SAVPF 98 96 97 99 100 101 102 121 127 120 125 107 108 109 124 119 123 118 114 115 116
  c=IN IP4 0.0.0.0
  a=rtpmap:98 VP9/90000
  a=rtpmap:96 VP8/90000
  a=rtpmap:97 rtx/90000
  a=rtpmap:99 rtx/90000
  a=rtpmap:100 VP9/90000
  a=rtpmap:101 rtx/90000
  a=rtpmap:102 H264/90000
  a=rtpmap:121 rtx/90000
  a=rtpmap:127 H264/90000
  a=rtpmap:120 rtx/90000
  a=rtpmap:125 H264/90000
  a=rtpmap:107 rtx/90000
  a=rtpmap:108 H264/90000
  a=rtpmap:109 rtx/90000
  a=rtpmap:124 H264/90000
  a=rtpmap:119 rtx/90000
  a=rtpmap:123 H264/90000
  a=rtpmap:118 rtx/90000
  a=rtpmap:114 red/90000
  a=rtpmap:115 rtx/90000
  a=rtpmap:116 ulpfec/90000
  a=fmtp:98 profile-id=0
  a=fmtp:97 apt=96
  a=fmtp:99 apt=98
  a=fmtp:100 profile-id=2
  a=fmtp:101 apt=100
  a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
  a=fmtp:121 apt=102
  a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f
  a=fmtp:120 apt=127
  a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
  a=fmtp:107 apt=125
  a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
  a=fmtp:109 apt=108
  a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f
  a=fmtp:119 apt=124
  a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f
  a=fmtp:118 apt=123
  a=fmtp:115 apt=114
  a=rtcp:9 IN IP4 0.0.0.0
  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=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=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=rtcp-fb:102 goog-remb
  a=rtcp-fb:102 transport-cc
  a=rtcp-fb:102 ccm fir
  a=rtcp-fb:102 nack
  a=rtcp-fb:102 nack pli
  a=rtcp-fb:127 goog-remb
  a=rtcp-fb:127 transport-cc
  a=rtcp-fb:127 ccm fir
  a=rtcp-fb:127 nack
  a=rtcp-fb:127 nack pli
  a=rtcp-fb:125 goog-remb
  a=rtcp-fb:125 transport-cc
  a=rtcp-fb:125 ccm fir
  a=rtcp-fb:125 nack
  a=rtcp-fb:125 nack pli
  a=rtcp-fb:108 goog-remb
  a=rtcp-fb:108 transport-cc
  a=rtcp-fb:108 ccm fir
  a=rtcp-fb:108 nack
  a=rtcp-fb:108 nack pli
  a=rtcp-fb:124 goog-remb
  a=rtcp-fb:124 transport-cc
  a=rtcp-fb:124 ccm fir
  a=rtcp-fb:124 nack
  a=rtcp-fb:124 nack pli
  a=rtcp-fb:123 goog-remb
  a=rtcp-fb:123 transport-cc
  a=rtcp-fb:123 ccm fir
  a=rtcp-fb:123 nack
  a=rtcp-fb:123 nack pli
  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://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=setup:actpass
  a=mid:1
  a=msid:- 91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=sendrecv
  a=ice-ufrag:ACjb
  a=ice-pwd:YSuamSFAtSftl3fFMK1DxZlB
  a=fingerprint:sha-256 79:F4:75:F0:F6:72:DF:B9:2C:2D:51:8A:7E:EA:29:73:27:3E:5A:21:0A:09:97:A9:0B:B9:AF:0C:83:0B:3B:0E
  a=ice-options:trickle
  a=ssrc:2206042804 cname:Z4s5Y/IGpkZKjhS2
  a=ssrc:2206042804 msid:- 91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc:2206042804 mslabel:-
  a=ssrc:2206042804 label:91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc:238469797 cname:Z4s5Y/IGpkZKjhS2
  a=ssrc:238469797 msid:- 91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc:238469797 mslabel:-
  a=ssrc:238469797 label:91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc-group:FID 2206042804 238469797
  a=rtcp-mux
  a=rtcp-rsize
  </code></pre>
  <p><strong>Peer 2 to Peer 3 Offer SDP</strong></p>
  <pre><code>v=0
  o=- 979727678423222728 2 IN IP4 127.0.0.1
  s=-
  t=0 0
  a=msid-semantic:  WMS
  a=group:BUNDLE 0 1
  m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 110 112 113 126
  c=IN IP4 0.0.0.0
  a=rtpmap:111 opus/48000/2
  a=rtpmap:103 ISAC/16000
  a=rtpmap:104 ISAC/32000
  a=rtpmap:9 G722/8000
  a=rtpmap:0 PCMU/8000
  a=rtpmap:8 PCMA/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
  a=fmtp:111 minptime=10;useinbandfec=1
  a=rtcp:9 IN IP4 0.0.0.0
  a=rtcp-fb:111 transport-cc
  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=setup:actpass
  a=mid:0
  a=msid:- a9dfc3b2-bb66-4bdd-930a-cd6768c65122
  a=sendrecv
  a=ice-ufrag:3CUq
  a=ice-pwd:t0ShMm9lUZI/3fvBV2kCHXWL
  a=fingerprint:sha-256 C2:98:3B:88:83:6A:F3:92:55:F7:B6:D3:D1:38:C8:B8:AA:D7:A5:B5:65:89:77:25:31:52:07:A0:94:6C:D7:6B
  a=ice-options:trickle
  a=ssrc:977782941 cname:hJih6KktIc1yo/Qx
  a=ssrc:977782941 msid:- a9dfc3b2-bb66-4bdd-930a-cd6768c65122
  a=ssrc:977782941 mslabel:-
  a=ssrc:977782941 label:a9dfc3b2-bb66-4bdd-930a-cd6768c65122
  a=rtcp-mux
  m=video 9 UDP/TLS/RTP/SAVPF 98 96 97 99 100 101 102 121 127 120 125 107 108 109 124 119 123 118 114 115 116
  c=IN IP4 0.0.0.0
  a=rtpmap:98 VP9/90000
  a=rtpmap:96 VP8/90000
  a=rtpmap:97 rtx/90000
  a=rtpmap:99 rtx/90000
  a=rtpmap:100 VP9/90000
  a=rtpmap:101 rtx/90000
  a=rtpmap:102 H264/90000
  a=rtpmap:121 rtx/90000
  a=rtpmap:127 H264/90000
  a=rtpmap:120 rtx/90000
  a=rtpmap:125 H264/90000
  a=rtpmap:107 rtx/90000
  a=rtpmap:108 H264/90000
  a=rtpmap:109 rtx/90000
  a=rtpmap:124 H264/90000
  a=rtpmap:119 rtx/90000
  a=rtpmap:123 H264/90000
  a=rtpmap:118 rtx/90000
  a=rtpmap:114 red/90000
  a=rtpmap:115 rtx/90000
  a=rtpmap:116 ulpfec/90000
  a=fmtp:98 profile-id=0
  a=fmtp:97 apt=96
  a=fmtp:99 apt=98
  a=fmtp:100 profile-id=2
  a=fmtp:101 apt=100
  a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
  a=fmtp:121 apt=102
  a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f
  a=fmtp:120 apt=127
  a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
  a=fmtp:107 apt=125
  a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
  a=fmtp:109 apt=108
  a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f
  a=fmtp:119 apt=124
  a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f
  a=fmtp:118 apt=123
  a=fmtp:115 apt=114
  a=rtcp:9 IN IP4 0.0.0.0
  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=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=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=rtcp-fb:102 goog-remb
  a=rtcp-fb:102 transport-cc
  a=rtcp-fb:102 ccm fir
  a=rtcp-fb:102 nack
  a=rtcp-fb:102 nack pli
  a=rtcp-fb:127 goog-remb
  a=rtcp-fb:127 transport-cc
  a=rtcp-fb:127 ccm fir
  a=rtcp-fb:127 nack
  a=rtcp-fb:127 nack pli
  a=rtcp-fb:125 goog-remb
  a=rtcp-fb:125 transport-cc
  a=rtcp-fb:125 ccm fir
  a=rtcp-fb:125 nack
  a=rtcp-fb:125 nack pli
  a=rtcp-fb:108 goog-remb
  a=rtcp-fb:108 transport-cc
  a=rtcp-fb:108 ccm fir
  a=rtcp-fb:108 nack
  a=rtcp-fb:108 nack pli
  a=rtcp-fb:124 goog-remb
  a=rtcp-fb:124 transport-cc
  a=rtcp-fb:124 ccm fir
  a=rtcp-fb:124 nack
  a=rtcp-fb:124 nack pli
  a=rtcp-fb:123 goog-remb
  a=rtcp-fb:123 transport-cc
  a=rtcp-fb:123 ccm fir
  a=rtcp-fb:123 nack
  a=rtcp-fb:123 nack pli
  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://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=setup:actpass
  a=mid:1
  a=msid:- 91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=sendrecv
  a=ice-ufrag:3CUq
  a=ice-pwd:t0ShMm9lUZI/3fvBV2kCHXWL
  a=fingerprint:sha-256 C2:98:3B:88:83:6A:F3:92:55:F7:B6:D3:D1:38:C8:B8:AA:D7:A5:B5:65:89:77:25:31:52:07:A0:94:6C:D7:6B
  a=ice-options:trickle
  a=ssrc:3489383016 cname:hJih6KktIc1yo/Qx
  a=ssrc:3489383016 msid:- 91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc:3489383016 mslabel:-
  a=ssrc:3489383016 label:91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc:4015488218 cname:hJih6KktIc1yo/Qx
  a=ssrc:4015488218 msid:- 91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc:4015488218 mslabel:-
  a=ssrc:4015488218 label:91063381-d7d3-43c0-af9b-9bb4a55b5ef6
  a=ssrc-group:FID 3489383016 4015488218
  a=rtcp-mux
  a=rtcp-rsize
  </code></pre>