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.
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.
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.
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.
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.
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 });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With