更改getusermedia流已经创建后分辨率
我有一个React应用程序,可以记录用户的网络摄像头,我正在实现一个功能,以允许用户更改视频分辨率。当我首次通过默认视频的宽度和高度创建媒体流
时,它可以正常工作,但是当我更改分辨率时,什么也没发生,我仍然能够记录网络摄像头改变。以下代码用于获取媒体流
,width
和height
变量可以是1280x720
或640x360
。上面提到的默认值是1280x720
,如果我使用640x360 640x360
代码>它有效。
const stream = await navigator.mediaDevices.getUserMedia({
video: {
width: {
ideal: width
},
height: {
ideal: height
},
frameRate: 25,
deviceId: { exact: videoInputId || cameraDeviceId },
aspectRatio: {
exact: width / height,
},
},
audio: audio,
});
cameraVideoRef.current.srcObject = stream;
setCameraStream(stream);
I have a React app that records the user's webcam I'm implementing a feature to allow the user to change the video resolution. When I create the Media Stream
for the first time passing a default video's width and height it works fine, however when I change the resolution nothing happens I'm still able to record the webcam but the resolution does not change. The following code is used to get the Media Stream
, the width
and height
variables could be 1280x720
or 640x360
. The default value mentioned above is 1280x720
and I can't change it to 640x360
after I the stream is created, if I create the stream using the 640x360
it works though.
const stream = await navigator.mediaDevices.getUserMedia({
video: {
width: {
ideal: width
},
height: {
ideal: height
},
frameRate: 25,
deviceId: { exact: videoInputId || cameraDeviceId },
aspectRatio: {
exact: width / height,
},
},
audio: audio,
});
cameraVideoRef.current.srcObject = stream;
setCameraStream(stream);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要再次使用新约束来调用
getusermedia()
,以获取新的流
对象,并使用浏览器相机的新分辨率获得。为了获得最佳结果,首先要停止其所有轨道,首先关闭旧流对象。You need to call
getUsermedia()
again, with new constraints, to get a newstream
object with a new resolution from a browser's camera. For best results close the old stream object first, by stopping all its tracks.