Get maximum video resolution with getUserMedia

后端 未结 7 1066
天命终不由人
天命终不由人 2020-12-13 18:17

I\'m trying to get highest video resolution as possible through JS navigator.getUserMedia. I know about constraints, but don\'t know how to choose right in my c

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 18:57

    Use:

    var constraints = { 
        video: {
            width: { ideal: 4096 },
            height: { ideal: 2160 } 
        } 
    };
    

    This will make the browser use the maximum resolution available, up to 4K. Works in Chrome 63, Edge 41 and Firefox 58.

    Citing MDN regarding the use of ideal:

    An ideal value, when used, has gravity, which means that the browser will try to find the setting (and camera, if you have more than one), with the smallest fitness distance from the ideal values given.

提交回复
热议问题