maartenbreddels / ipywebrtc

WebRTC for Jupyter notebook/lab
MIT License
243 stars 40 forks source link

Using external webcam #65

Open sugeknowles opened 5 years ago

sugeknowles commented 5 years ago

How do I create a CameraStream object for an external webcam connected to my system? The computer has a front and rear facing camera, but I need to use a specialized camera that shows up as another webcam on the computer. I am not sure how to create the constraints to use this camera.

martinRenou commented 5 years ago

Here are some documentations for the deviceId in the constraints: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Parameters

You can use this method to list all your devices: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices

Just execute:

if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  console.log("enumerateDevices() not supported.");
  return;
}

// List cameras and microphones.

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);
});

in the Chrome/Firefox dev tools console, and you should see your deviceId hopefully.

I'm not sure we can provide a Python API for that