在 webrtc 中即时控制视频发送帧率 [英] Control video send framerate on the fly in webrtc

查看:112
本文介绍了在 webrtc 中即时控制视频发送帧率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我使用报价 SDP 中的 b=AS:1000 来设置上行视频的上限(即 1Mbps),以控制我发送到远程对等方的视频量.我正在研究一种不同的方法,所以我想知道是否有办法控制当前活动视频会话中的视频帧速率?

我发现 getUserMedia 支持 minFrameRate 和 maxFrameRate 参数.那么我可以在我的对等连接处于会话中时调用 getUserMedia 吗?另一个类似的合理用例是能够在我已经处于对等会话中时更换相机?无需重新协商 SDP、ICE、...这可行吗?

解决方案

你问了几个问题,当第一次写这个答案时,对大多数问题的简短回答是:还没有(尽管由于 DJ House 的下面的回答,我已经更新了它!)..>

应用约束

您应该能够在活动会话期间更改约束,使用 applyConstraints 像这样:

const videotrack = stream_from_getUserMedia.getVideoTracks()[0];videotrack.applyConstraints({ frameRate: { max: 10 } });

今天的大多数实现都能够降低帧速率,而不仅仅是提供相机中可用的模式.

试试这个小提琴.

RTCRtpSender

您应该能够控制编码&使用 setParameters 在发送方对象中传输:

const pc = RTCPeerConnection(config);const videotrack = stream.getVideoTracks()[0];const sender = pc.addTrack(videotrack, stream);//首先获取当前参数const params = sender.getParameters();if (!params.encodings) params.encodings = [{}];//火狐解决方法!params.encodings[0].maxBitrate = 60000;params.encodings[0].scaleResolutionDownBy = 2;sender.setParameters(params);

encodings 是一个数组,但除非使用联播,否则只有一个条目.

试试这个小提琴!(在 Chrome、Firefox、Safari 和 Edge 中测试!)

RTCRtpSender.replaceTrack

您还应该能够在正在进行的对等会话中替换摄像机轨迹,如下所示:

const videotrack2 = a_different_stream.getVideoTracks()[0];等待 sender.replaceTrack(videotrack2);

它改变了遥控器看到的东西,而不会改变这端的东西.在这个小提琴中尝试一下.

Right now I use the b=AS:1000 in the offer SDP to set the upper limit(i.e. 1Mbps) for the upstream video to control the amount of video I am sending to the remote peer. I am looking into a different approach, so I was wondering if there is a way to control video frame rate on the fly of the current active video session?

EDIT: I found out that getUserMedia supports minFrameRate and maxFrameRate parameters. So can I call getUserMedia while my peer connection is in session? Another similar use case, which find reasonable, is to be able to change the camera while I am already in a peer session? Without having to renegotiate SDPs, ICE, ... Is this doable?

解决方案

You're asking several questions, and when this answer was first written, the short answer to most of them was: not yet (though I've since updated it thanks to DJ House's answer below!).

applyConstraints

You should be able to alter constraints during an active session, using applyConstraints like this:

const videotrack = stream_from_getUserMedia.getVideoTracks()[0];
videotrack.applyConstraints({ frameRate: { max: 10 } });

Most implementations today are able to decimate frame rates and not just deliver the modes available in the camera.

Try this fiddle.

RTCRtpSender

You should be able to control encoding & transmission in the sender object using setParameters:

const pc = RTCPeerConnection(config);

const videotrack = stream.getVideoTracks()[0];
const sender = pc.addTrack(videotrack, stream);

// get the current parameters first
const params = sender.getParameters();

if (!params.encodings) params.encodings = [{}]; // Firefox workaround!

params.encodings[0].maxBitrate = 60000;
params.encodings[0].scaleResolutionDownBy = 2;
sender.setParameters(params);

encodings is an array, but unless simulcast is used, there's just one entry.

Try this fiddle! (tested in Chrome, Firefox, Safari & Edge!)

RTCRtpSender.replaceTrack

You should also be able to replace the camera track in an ongoing peer session, like this:

const videotrack2 = a_different_stream.getVideoTracks()[0];
await sender.replaceTrack(videotrack2);

It alters what the remote sees, without altering things at this end. Try it in this fiddle.

这篇关于在 webrtc 中即时控制视频发送帧率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆