jhuckaby / webcamjs

HTML5 Webcam Image Capture Library with Flash Fallback
MIT License
2.5k stars 1.11k forks source link

Select from multiple cameras #313

Open nitesh-nair opened 4 years ago

nitesh-nair commented 4 years ago

If i have an external camera connected, is there a way to select that from the page rather than going into chrome settings and changing it?

usamaraja125 commented 4 years ago

hi did you find the answer i want to connect IP camera .please let me know if you know how to connect IP camera

t-walker-wei commented 3 years ago

From enumerateDevices, you can get the list of available cameras. And then use contraints option in webcamjs deviceId: { exact: [the device id you get from enumerateDevices] }

kentxp commented 3 years ago
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    console.log(device.kind + ": " + device.label +
                " id = " + device.deviceId);
  });
})
.catch(function(err) {
  console.log(err.name + ": " + err.message);
});
// when you get device.deviceId,you can replace xxx in  deviceId: {exact: 'xxx' },
        Webcam.set({
            width: 320,
            height: 180,
            image_format: 'jpeg',
            jpeg_quality: 90,
            constraints: {
                width: 320, // { exact: 320 },
                height: 180, // { exact: 180 },
                facingMode: 'user',
                deviceId: {exact: 'xxx' },
                frameRate: 30
            }
        });
        Webcam.attach( '#my_camera' );