更改getusermedia流已经创建后分辨率

发布于 2025-01-27 06:10:14 字数 876 浏览 6 评论 0原文

我有一个React应用程序,可以记录用户的网络摄像头,我正在实现一个功能,以允许用户更改视频分辨率。当我首次通过默认视频的宽度和高度创建媒体流时,它可以正常工作,但是当我更改分辨率时,什么也没发生,我仍然能够记录网络摄像头改变。以下代码用于获取媒体流widthheight变量可以是1280x720640x360。上面提到的默认值是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆夏时光 2025-02-03 06:10:14

您需要再次使用新约束来调用getusermedia(),以获取新的对象,并使用浏览器相机的新分辨率获得。为了获得最佳结果,首先要停止其所有轨道,首先关闭旧流对象。

You need to call getUsermedia() again, with new constraints, to get a new stream object with a new resolution from a browser's camera. For best results close the old stream object first, by stopping all its tracks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文