Reputation: 209625
I am using navigator.mediaDevices.getUserMedia()
on Chrome 80 on Linux. In order to get the highest quality, I run through a range of constraints, checking for errors, or for the stream not actually being of the desired size. For at least one of my cameras, it frequently only gets the 640x480 size, not the 1280x720 that it's capable of. If I call getUserMedia()
for a different device and then go back and call it for the original device, it generally, but not always, gets the 1280x720 version. I'm not sure how I can force Chrome to use the right dimensions.
These are the constraints that I have it use (in sequence):
// OverconstrainedError (deviceId)
{"audio":false,"video":{"deviceId":{"exact":"cd059d931e1c4554faee7a5722ab8db810cec27316cc085512fcf5815dac3a98"},"frameRate":30,"width":{"min":1920,"ideal":1920,"max":1920},"height":{"min":1080,"ideal":1080,"max":1080}}}
// succeeds, but returns 640x480
{"audio":false,"video":{"deviceId":{"exact":"cd059d931e1c4554faee7a5722ab8db810cec27316cc085512fcf5815dac3a98"},"frameRate":30,"width":{"ideal":1920},"height":{"ideal":1080}}}
// OverconstrainedError (deviceId)
{"audio":false,"video":{"deviceId":{"exact":"cd059d931e1c4554faee7a5722ab8db810cec27316cc085512fcf5815dac3a98"},"frameRate":30,"width":{"min":1920},"height":{"min":1080}}}
// OverconstrainedError (deviceId)
{"audio":false,"video":{"deviceId":{"exact":"cd059d931e1c4554faee7a5722ab8db810cec27316cc085512fcf5815dac3a98"},"frameRate":30,"width":{"exact":1920},"height":{"exact":1080}}}
// succeeds, but returns 640x480
{"audio":false,"video":{"deviceId":{"exact":"cd059d931e1c4554faee7a5722ab8db810cec27316cc085512fcf5815dac3a98"},"frameRate":30,"width":1920,"height":1080}}
And then the same pattern for 1600x1200, 1280x720, 800x600 and 640x480. The last succeeds ultimately because it matches the only dimensions ever returned from getUserMedia()
.
This works fine on Firefox. It works fine for some devices. It works sometimes if I select a different device after the first one has loaded with the low dimensions.
The fact that the OverconstrainedError
says that the offending constraint is deviceId
is slightly concerning, but based on what I've read, it just returns the first constraint, not necessarily the one that failed. In any case, it's hard to see how the device ID would cause it to fail, when other variants don't fail.
What do I need to do to make this work?
Upvotes: 6
Views: 8295
Reputation: 209625
I was doing a call to getUserMedia()
before calling enumerateDevices()
, in order to have permission to see device names. That call was using the constraints {video:true, audio:true}
. In Chrome, at least, this gets the lowest resolution. Further calls for the same device will always return the same resolution it appears. To fix this, I replaced the true
with a suitably large width and height {video:{width:4096,height:2160}}
and now Chrome gets the highest resolution in subsequent calls!
Upvotes: 12