5

I'm trying to use getUserMedia to show the cam live stream on a web page. It works (if I save the stream to a file, it is ok) but the video tag show only a static green image as preview. Is anyone facing the same problem?

My setup:

  • Samsung S8 (SM-G950F)
  • Android 9
  • Chrome 107.0.5304.91

HTML

<video autoplay="true" width="100%" id="video-test"></video>

JS

var video = document.querySelector("#video-test");

navigator.mediaDevices.getUserMedia({
      video: {
        mandatory: { minFrameRate: 10, minWidth: 100, minHeigth: 100  },
      }
 })
 .then(function (stream) {
      video.srcObject = stream;
 })
 .catch(function (err0r) {
      console.log("Something went wrong!", err0r);
 });

Result green screen

Thank you

  • Were you able to fix your issue? I stumbled upon the same issue and I noticed that on my phone (p20 pro) I didn't have the problem until I updated chrome – Daniel Baychev May 11 '23 at 11:37

1 Answers1

1

Ah, the green screen of death. Why is it green? Because it's trying to display an all-zero YUV image.

Your constraints in your call to .getUserMedia() are incorrect. mandatory is no longer a thing. You need something like this:

{
  video: {
    width: { min: 100, ideal: 320 },
    height: { min: 100, ideal: 240 },
    frameRate: { min: 10, ideal: 10 }
  }
}

It's an inconvenient truth that you have to muck around to get constraints values that work on many different platforms. And, you have to accept what gUM gives you. If you demand exact constraints using something like frameRate: { exact: 10 } you may get an OverconstrainedError exception, or some other exception.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • 1
    I'm seeing this problem as well on an Samsung Galaxy A8 on Chrome 114 (latest at the time of writing). It's *NOT* an all-zero YUV image, here it seems to be merely a display issue. I know it's not all-zero because I'm reading QR codes from it. But the video feed that is displayed in the video element is all-green. I'm pretty sure this is a browser issue, as things were working previously. – Alex Suzuki Jun 26 '23 at 13:34
  • 3
    Oh, never mind, it seems to be a Chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1455752&q=getusermedia%20green&can=2 – Alex Suzuki Jun 26 '23 at 13:41