gpt4 book ai didi

javascript - 使用 focusMode 约束获取所需的媒体设备

转载 作者:行者123 更新时间:2023-12-05 04:46:13 29 4
gpt4 key购买 nike

大家好!

目前,我正在为我的网络应用程序实现二维码扫描器。在多个设备上进行一些测试后,我注意到我必须设置 focusMode 约束才能获得能够自动对焦环境的相机。

我可以通过在约束中直接设置 deviceId 来直接在我的调试设备上选择摄像头,如下所示:

let stream = await navigator.mediaDevices.getUserMedia({
video: {
deviceId: "332d34c91861f97ba8f0e11f446da4566a1803539764dd67c1dfe036ef32fd97"
}
});

我可以调用 stream.getVideoTracks()[0].getCapabilities() 来获取功能。

{
aspectRatio: {max: 4000, min: 0.0003333333333333333},
colorTemperature: {max: 7000, min: 2850, step: 50},
deviceId: "332d34c91861f97ba8f0e11f446da4566a1803539764dd67c1dfe036ef32fd97",
exposureCompensation: {max: 2, min: -2, step: 0.10000000149011612},
exposureMode: (2) ["continuous", "manual"],
exposureTime: {max: 1250, min: 0, step: 0},
facingMode: ["environment"],
focusMode: (3) ["manual", "single-shot", "continuous"],
frameRate: {max: 30, min: 0},
groupId: "40f2953f5fae495c7471348c844e919762a3213019b271664d220d0aa617313c",
height: {max: 3000, min: 1},
iso: {max: 4000, min: 20, step: 1},
resizeMode: (2) ["none", "crop-and-scale"],
torch: true,
whiteBalanceMode: (2) ["continuous", "manual"],
width: {max: 4000, min: 1}
}

Copied from the Chromium console log.

因此,我通过 Brave(基于 Chromium)在我的三星 Galaxy A51 上进行远程调试尝试了以下约束,但均无效:

let stream = await navigator.mediaDevices.getUserMedia({
video: {
focusMode: {exact: ["continuous"]}
}
});


let stream = await navigator.mediaDevices.getUserMedia({
video: {
focusMode: "continuous"
}
});


let stream = await navigator.mediaDevices.getUserMedia({
video: {
focusMode: ["continuous"]
}
});


let stream = await navigator.mediaDevices.getUserMedia({
video: {
advanced: [{focusMode: "continuous"}]
}
});


let stream = await navigator.mediaDevices.getUserMedia({
video: {
advanced: [{focusMode: ["continuous"]}]
}
});


let stream = await navigator.mediaDevices.getUserMedia({
video: {
advanced: [{focusMode: {exact: "continuous"}}]
}
});

我不知道结构是否正确,也不太确定如何找到它。

有人知道如何使用 focusMode 约束来获得具有连续对焦模式的设备吗?

最佳答案

来自:documentation

The process works like this (using MediaStreamTrack as an example):

  1. If needed, call MediaDevices.getSupportedConstraints() to get thelist of supported constraints, which tells you what constrainableproperties the browser knows about. This isn't always necessary,since any that aren't known will be ignored when you specifythem—but if you have any that you can't get by without, you canstart by checking to be sure they're on the list.

  2. Once the script knows whether the property or properties it wishes to use are supported, it can then check the capabilities of the APIand its implementation by examining the object returned the track'sgetCapabilities() method; this object lists each supported constraintand the values or range of values which are supported.

  3. Finally, the track's applyConstraints() method is called to configure the API as desired by specifying the values or ranges ofvalues it wishes to use for any of the constrainable properties aboutwhich it has a preference.

  4. The track's getConstraints() method returns the set of constraints passed into the most recent call to applyConstraints().This may notrepresent the actual current state of the track, due to propertieswhose requested values had to be adjusted and because platform defaultvalues aren't represented. For a complete representation of thetrack's current configuration, use getSettings().

In the Media Stream API, both MediaStream and MediaStreamTrack haveconstrainable properties.

可能您的 focusMode 是默认设置,您的手机会自行计算。所以你必须使用 getSettings() 来返回实际值。

.getSettings() 返回什么?

关于javascript - 使用 focusMode 约束获取所需的媒体设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68912208/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com