使用getUserMedia获得最大的视频分辨率 [英] Get maximum video resolution with getUserMedia

查看:333
本文介绍了使用getUserMedia获得最大的视频分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过JS navigator.getUserMedia 获得最高的视频分辨率.我了解约束条件,但不知道如何选择合适的情况.

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 case.

问题似乎是无法说我想要最大分辨率的视频".因此,我想说的是我想要的视频分辨率不低于非常大的分辨率".

The problem is looks like there is no way to say "I want a video at maximum resolution". So instead I'm trying to say "I want video not less than very big resolution".

当我尝试使用 minWidth:1600 时,Chrome浏览器返回了1280×720的视频(我认为是相机中最高的).但是,如果用户拥有更高分辨率的相机怎么办?因此,我要求提供 minWidth:2048 视频,而Chrome仅返回640×480.

When I'm trying minWidth: 1600, Chrome returns me 1280×720 video (highest possible for my camera, I think). But what if user has camera with higher resolution? So I'm asking for minWidth: 2048 video, and Chrome returns only 640×480.

var constraints = {
  video: {
    optional: [
    {minWidth: 2048}
    ]
  }
};

这是在线示例: http://jsbin.com/kibeza/1/watch?js,输出

还有一个实际问题:Chrome不懂数学.它认为1600大于2048.我不能要求视频不少于100500",因为在这种情况下,我将获得标准的低分辨率.我不能要求视频不少于合理的小分辨率",因为可以有更高分辨率的用户,而我想获得更高的分辨率.

And there is actual problem: Chrome doesn't know math. It think what 1600 is greater than 2048. I can't ask for video "not less than 100500", because in this case I'll get standard low resolution. I cant ask video "not less than some reasonable small resolution", because there can be users with higher resolution and I want to get higher resolution.

推荐答案

使用:

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

这将使浏览器使用可用的最大分辨率,最高为4K.在Chrome 63,Edge 41和Firefox 58中均可使用.

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

引用 MDN 关于理想:

理想值在使用时具有重力,这意味着浏览器会尝试找到设置(如果有多个,请选择相机),与给定的理想值之间的最小健身距离.

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.

这篇关于使用getUserMedia获得最大的视频分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆