3

I'm trying to get the camera to focus on an object, by using focusMode on the stream track received from getUserMedia. But after changing the property of focus mode to manual mode, I don't see it reflect on the stream also I could see that after applying focusMode constraint it stays unchanged(focusMode: continuous). The issue is when I capture an image, using the stream, the image is blurry because of lack of focus.

Here is a code snippet.


navigator.mediaDevices.getUserMedia({ video: true })
        .then((stream) => {
          video.srcObject = stream;
          track = stream.getVideoTracks()[0];
          track.applyConstraints({
            advanced: [
              { focusMode: 'manual', focusDistance: 0.33 }
            ]
          })
        });

Does anybody have experience with getting the camera to focus using the manual or single-shot mode? Any help is appreciated.

  • Thanks for the edit. It clears up you do have a camera where `track.getSettings()` reveal support for *focusMode*. I'm not seeing that on mine, so I guess I either don't have the right camera, or don't know how to turn on this feature, so I probably won't be much help—Have you tried `track.applyConstraints({focusMode: 'manual', focusDistance: 0.33})`? – jib Mar 15 '19 at 15:50
  • Seems like this has been [asked before](https://stackoverflow.com/questions/53649030/changing-focusmode-not-working-using-mediastream-api-in-google-chrome). No solution though. – jib Mar 15 '19 at 15:58

0 Answers0