英文:
MediaTrackConstraints: aspectRatio property not working on mobile brwosers
问题
我正在尝试在Web应用程序中使用aspectRatio视频约束来强制设置HTML视频录制器的特定纵横比:
```js
const videoConstraints = {
aspectRatio: 9 / 16,
facingMode: 'user'
};
在桌面版的Chrome浏览器中可以正常工作,但在移动浏览器中纵横比似乎不起作用。
这是移动浏览器的已知限制吗?还是我的实现可能存在问题?如果这是一个限制,是否有任何解决方法可以在移动设备上强制设置纵横比?
提前感谢您的任何见解。
<details>
<summary>英文:</summary>
I'm trying to enforce a specific aspect ratio for an HTML video recorder using aspectRatio video constraint in a web app:
```js.
const videoConstraints = {
aspectRatio: 9 / 16,
facingMode: 'user'
};
It works on desktop Chrome, but the aspect ratio doesn't apply on mobile browsers.
Is this a known limitation of mobile browsers or could there be a problem with my implementation? If it's a limitation, are there any workarounds to enforce an aspect ratio on mobile?
Thanks in advance for any insights.
答案1
得分: 1
constraints 您传递给 getUserMedia() (gUM) 的是建议。设备中的许多录制子系统无法提供精确的约束。这在移动设备上尤为明显,因为它们的摄像头有时具有固定的分辨率。您提供所需的约束,然后接受或拒绝它给出的内容。
另一点需要记住的是,将设备旋转(从垂直或纵向模式到水平或横向模式)会改变可用的约束。
我发现解决这个问题的唯一方法是尝试不同的组合。如果您正在寻找9/16纵向模式,请尝试这样的约束:
const constraints = {
width: {min: 360, ideal: 720, max:1440},
height: {min: 640, ideal:1280; max:1920}
}
不幸的是,要使这些内容可靠地工作需要大量的尝试。
英文:
The constraints you pass to getUserMedia() (gUM) are suggestions. Many recording subsystems in devices cannot deliver precise constraints. This is especially true of aspect-ratio constraints on mobile devices, as their cameras sometimes have fixed resolutions. You give it the constraints you want, and then you either accept or reject what it gives you.
The other thing to keep in mind is that rotating the device (from upright or portrait mode to horizontal or landscape mode) changes the available constraints.
The only way I have found to beat this problem is to try different combinations. Try constraints like these if you're looking for 9/16 portrait mode.
const constraints = {
width: {min: 360, ideal: 720, max:1440},
height: {min: 640, ideal:1280; max:1920}
}
Unfortunately, getting this stuff to work reliably takes a lot of fooling around.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论