vgo*_*129 1 javascript video-streaming webrtc getusermedia
我有以下代码可以在我的 Google Chrome 浏览器中流式传输连接的视频源。WebRTC 的getUserMedia就是这样做的。以下代码片段用于配置我的外部相机设备的分辨率和帧速率。
function configureVideo()
{
const video_constraints ={};
//Create the following keys for Constraint
video_constraints.video = {};
//set camera name
video_constraints.video.deviceId = {};
video_constraints.video.deviceId.exact = <device_id_comes_here>
//set resolution Width
video_constraints.video.width = {};
video_constraints.video.width.exact = 640;
//set resolution height
video_constraints.video.height = 480;
video_constraints.video.height.exact = streamHeight;
//set fps
video_constraints.video.frameRate = 60;
video_constraints.video.frameRate.exact = streamFps;
console.log("Selected Contraints is :", video_constraints);
navigator.mediaDevices.getUserMedia(video_constraints).then(streamCallback).catch(handleError);
}
Run Code Online (Sandbox Code Playgroud)
是的,我成功地从我的外部相机设备流式传输视频。相机提供 2 种类型的帧格式 YUYV 和 BY8。但我真的不知道当前正在流式传输什么帧格式。
有什么方法可以在 WebRTC 中配置我感兴趣的视频帧格式。
回答您的问题“是否有任何方法可以在 WebRTC 中配置我感兴趣的视频帧格式。” 答案是否定的……这很令人沮丧!
您必须获取流并将其渲染到画布以获取数据,然后进行转换......这主要是由于MediaCapture 的功能和框架可能经历的转换(取决于浏览器实现)。您可以使用ImageCapture获得更多相机属性(并将其作为ImageBitmap 获取),但目前的支持非常薄弱。
请阅读下面我的回答,其中更深入地介绍了 MediaCapture 和 ImageCapture 的用例,以获取更多信息。
为什么 iPad / iOS 上的原生相机分辨率 -vs- getUserMedia 存在差异?