Search code examples
webrtcelectronwebcamgetusermedia

Using a 4k Logitech webcam with WebRTC/getUserMedia


I have a 4k Logitech brio webcam and I can pull live video from it using WebRTC/getUserMedia. Sadly only in HD 1920x1080 … is there any way to use the 4k capabilities of the camera in the browser/electron app?

I'm working on a single instance media installation, so cross browser support is not an issue. I'm targeting towards whatever webkit electron-builder will package.

Thanks!


Solution

  • getUserMedia can be very... peculiar currently in most browsers, electron included.

    First, make sure you are using your constraints correctly. To get 4k you should be trying something similar to this:

    {
      audio: false,
      video: {
        width: { exact: 3840 },
        height: { exact: 2160 }
      }
    }
    

    Then if that works, go from there on toning down the constraints to get other non-UHD webcams to work. Make sure you read up on the constraints and what is possible here, and always include the WebRTC adapter.js even in the latest version of electron it is still needed (mainly for converstion of error names to the proper "standard" ones).

    Most likely you will end up with a constraints setup similar to this:

    {
      audio: false,
      video: {
        width: {
          min: 1280,
          ideal: 3840,
          max: 3840
        },
        height: {
          min: 720,
          ideal: 2160,
          max: 2160
        }
      }
    }
    

    That will make the browser attempt to get a 4k resolution, but then will step down to a minimum of 720p if needed.

    Also, if you want to check if your browser/camera supports UHD correctly, you can always try this website which will run a test to get which resolutions getUserMedia supports on your system.

    And finally, make sure you are choosing the right camera. Many new devices are including multiple environment-facing cameras, and if you don't define the deviceId you want to use, the useragent will pick for you, and they often choose poorly (for example, a Kyocera phone I recently worked with used a wide-angle lens by default unless told otherwise, and the wide-angle lens didn't support any "normal" resolutions making it fallback to a very low resolution and very strange aspect ratio.