WebRTC firefox 约束

WebRTC firefox constraints

我目前在个人开发中使用 WebRTC,一切正常。我从我的网络摄像头获取流,但现在我想对 getUserMedia().

使用约束
var constraints = {
           audio: false,
           video: {
               mandatory : {
                     minWidth: 1280,
                     minHeight: 720 
               }
           }
};

当我在 Firefox 中测试它时,它似乎忽略了约束。当我在 Chrome 或 Opera 上测试时,我的约束工作正常并且我的质量很好,有人知道为什么吗? Firefox 的问题?

谢谢你的建议

编辑 wiki link 好像过时了,请参考

好像是Firefox has not yet implemented constraints.

Constraints have been implemented since Chrome 24 and Opera 18. These can be used to set values for video resolution for getUserMedia() and RTCPeerConnection addStream() calls.

来自:https://wiki.mozilla.org/Media/getUserMedia

Capture resolution [in Firefox] currently fixed to 640x480 for video;

只支持

Minimal constraints supported: (Note: all of these booleans default to 'false') video: true/false audio: true/false fake: true/false picture: true/false

Firefox does support getUserMedia() 约束的子集,但不是 Chrome 和 Opera 使用的过时语法。 mandatory / optional 语法在几年前就被弃用了,minWidthminHeight 在前一年被弃用。

MediaCapture 规范

According to the specification,现在稳定了,你的例子应该这样写:

var constraints = {
    audio: false,
    video: {
        width: { min: 1280 },
        height: { min: 720 },
    }
};

这适用于 Firefox(以及 Chrome 和 adapter.js):https://jsfiddle.net/34qxx5w1

在规范中,关键字 minmaxexact (a.k.a.min == max) 本质上是强制性的,而普通值和 ideal 不是。这是一个更完整的例子:

var constraints = {
    audio: false,
    video: {
        width: { min: 1024, ideal: 1280, max: 1920 },
        height: { min: 576, ideal: 720, max: 1080 },
    }
};

这在 Firefox 中有效(在简单的情况下 Chrome 使用 adapter.js polyfill)。

一个 ideal 值在使用时具有重力,这意味着浏览器将尝试找到设置(和相机,如果你有多个),最小的 fitness distance从给定的理想值。

普通值本质上是理想的,这意味着:

var constraints = { video: { width: 640, height: 480 } };

等同于:

var constraints = { video: { width: { ideal: 640 }, height: { ideal: 480 } } };

换句话说,getUserMedia() 将尝试遵守但绝不会失败的首选项。

如果您必须具有特定的分辨率,请使用此 shorthand:

var constraints = { video: { width: { exact: 640 }, height: { exact: 480 } } };

火狐

截至目前,Firefox 支持 widthheightframeRate 和(在移动设备上)facingMode。另外,一些版本注意事项:

  • FF32-37: 不支持纯值和 ideal。但是,值不是强制性的,除非您添加非规范 require 关键字。

  • FF38+: 实现上述约束的规范。改进了 Mac 相机的处理(尽管 frameRate 对 Mac 有限制)。

  • FF43+: 实现 MediaStreamTrack.applyConstraints()mediaDevices.getSupportedConstraints().

  • FF46+: 实现 echoCancellation.