Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the bitrate of webrtc?

I'm using webrtc to send a 1080p video stream from one tab to another tab on the same computer(windows10, chrome 76). And the receiver's video quality is not as good as sender's. The bitrate is only about 2400kbps(300kb/s), no difference between 1080p and 720p. Video resolution also become lower when the camera moving.
How can I improve the quality of webrtc video stream?

I have tried to modify sdp to increase bitrate. http://www.rtcbits.com/2016/11/controlling-bandwidth-usage-in-webrtc.html

set x-google-max-bitrate

peer.createAnswer().then(sdp => {
  var arr = sdp.sdp.split('\r\n');
  arr.forEach((str, i) => {
    if (/^a=fmtp:\d*/.test(str)) {
      arr[i] = str + ';x-google-max-bitrate=28000;x-google-min-bitrate=0;x-google-start-bitrate=20000';
    }
  });
  sdp = new RTCSessionDescription({
    type: 'answer',
    sdp: arr.join('\r\n'),
  })
  peer.setLocalDescription(sdp);
  socket.emit('message_send', { type: 'answer', sdp: sdp.sdp });
});

output receive rate (kb/s)

var prevReport = null;
var t = setInterval(function() {
  if (!peer) {
    prevReport = null;
    return;
  }
  peer.getStats(null).then(reporter => {
    reporter.forEach(report => {
      if (report.type === 'inbound-rtp' && report.mediaType === 'video') {
        if (!prevReport) {
          prevReport = report;
        } else {
          console.log((report.bytesReceived - prevReport.bytesReceived) / (report.timestamp - prevReport.timestamp));
        }
      }
    });
  });
}, 1000);

I hope that the bitrate of 1080p could be obviously greater than of 720p.
Is there a way to let webrtc transport lossless or low-loss video stream?


The 300kb/s limit only exists when a chrome tab sends video to another chrome tab. When a chrome tab sends video to a firefox tab, the x-google-max-bitrate works.

like image 991
cyh Avatar asked Aug 26 '19 07:08

cyh


People also ask

How do I increase video quality in WebRTC?

WebRTC makes its own decisions. These are based on the bitrate available. It will automatically decide to increase or reduce resolution and frame rate to accommodate for what it feels is the best quality. You can even pass hints on your content type – do you value motion over sharpness or vice versa.

What is bitrate in WebRTC?

In the context of VoIP (and WebRTC), bitrate is the number of bits per second that are being actively sent or received over the network. A few things to remember about bitrate: The maximum bitrate possible is capped by the bandwidth available, which can be dynamic throughout a single session.

Does WebRTC support adaptive bitrate?

Adaptive bitrate can be used with WebRTC, HLS, and CMAF/DASH. Traditional video streaming technologies relied on distributing a fixed bitrate video stream. If your network connection could not support that bitrate, you could not watch the video without dramatic buffering.

How much bandwidth does WebRTC use?

Current WebRTC implementations use Opus and VP8 codecs: The Opus codec is used for audio and supports constant and variable bitrate encoding and requires 6–510 Kbit/s of bandwidth.


1 Answers

I tried to set b=AS:10000 and it works.

peer.createAnswer().then(sdp => {
  var arr = sdp.sdp.split('\r\n');
  arr.forEach((str, i) => {
    if (/^a=fmtp:\d*/.test(str)) {
      arr[i] = str + ';x-google-max-bitrate=10000;x-google-min-bitrate=0;x-google-start-bitrate=6000';
    } else if (/^a=mid:(1|video)/.test(str)) {
      arr[i] += '\r\nb=AS:10000';
    }
  });
  sdp = new RTCSessionDescription({
    type: 'answer',
    sdp: arr.join('\r\n'),
  })
  peer.setLocalDescription(sdp);
  socket.emit('message_send', { type: 'answer', sdp: sdp.sdp });
});
like image 150
cyh Avatar answered Sep 22 '22 05:09

cyh