我将如何实现图像轨道设置



在 https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints 有一个名为"图像轨道的属性"的部分。如何调整这些设置?

当我运行navigator.mediaDevices.getSupportedConstraints()时,我得到以下内容:

{
  "aspectRatio": true,
  "brightness": true,
  "channelCount": true,
  "colorTemperature": true,
  "contrast": true,
  "depthFar": true,
  "depthNear": true,
  "deviceId": true,
  "echoCancellation": true,
  "exposureCompensation": true,
  "exposureMode": true,
  "facingMode": true,
  "focalLengthX": true,
  "focalLengthY": true,
  "focusMode": true,
  "frameRate": true,
  "groupId": true,
  "height": true,
  "iso": true,
  "latency": true,
  "pointsOfInterest": true,
  "sampleRate": true,
  "sampleSize": true,
  "saturation": true,
  "sharpness": true,
  "torch": true,
  "videoKind": true,
  "volume": true,
  "whiteBalanceMode": true,
  "width": true,
  "zoom": true
}

我可以在video下调整"视频轨道的属性"

navigator.mediaDevices.getUserMedia({
  video: {
    aspectRatio: 1.5,
    width: 1280,
  },
})

但是我不确定如何调整focalLengthXexposureCompensation等属性。我将在哪里调整这些?

从MDN中,我找到了一些描述该过程的文档。实质上,您可以使用每个约束的最小值和最大值来指定最小和最大可接受值。只有添加到约束选项对象的值才会更改。

  const constraints = {
  width: {min: 640, ideal: 1280, max: 1920},
  height: {min: 480, ideal: 720}
};
navigator.mediaDevices.getUserMedia({ video: true })
.then(mediaStream => {
  const track = mediaStream.getVideoTracks()[0];
  track.applyConstraints(constraints)
  .then(() => {
    // Do something with the track such as using the Image Capture API.
  }
  .catch(e => {
    // The constraints could not be satisfied by the available devices.
  }
}

https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/applyConstraints

理论上,这样的东西虽然感觉还是有点粗糙,但无法获得曝光

navigator.mediaDevices
.getUserMedia({
  video: {
    facingMode: "environment",
  },
})
.then((mediastream) => {
  const track = mediastream.getVideoTracks()[0];
  track.applyConstraints({
    advanced: [
      {
        focusMode: "manual",
        focusDistance: event.target.value,
      },
      {
        exposureMode: "continuous", // or single-shot
        exposureCompensation: event.target.value,
      },
    ],
  });
});

更多内容 https://www.w3.org/TR/image-capture/#exposure-compensation

我到目前为止的发现做了一个小代码笔:https://codepen.io/CanRau/pen/abqbWjd

同一事件(更多在代码笔中(设置焦点和曝光可能不是正确的做法,因为两者都可能具有从track.getCapabilities()对象获得的不同设置

编辑:不确定focalLengthX

最新更新