admin管理员组文章数量:1289891
In my browser application (with AngularJS
) I am making a connection to the webcam via the HTML5 getUserMedia API
. But for some reason the output stream is always in landscape mode
and not in portrait mode
. So I've tried a few things, but I cannot figure out how to get it into portrait mode. Any idea's?
Specs:
AngularJS: 1.6.5
IMac: 27" - MacOS high Sierra
Chrome: 61.0.3163.100 (64-bit)
My code
private static readonly videoOptions = {
mandatory: {
minWidth: 1080,
minHeight: 1920
}
};
private startCamera(): void {
navigator.mediaDevices.getUserMedia({video: MWWebcamController.videoOptions, audio: false})
.then((stream: MediaStream) => {
this.webcam = new WebcamStream(window.URL.createObjectURL(stream), stream);
})
.catch((exception) => {
console.error("Could not load the stream. due to: ", exception);
});
}
I've tried
- Rotating the video via CSS. This kind of works, but the stream won't be rotated with it.
- Settings the
mendatory
property on the videoOptions to{ height:1920, width: 1080 }
, but this results in an error from the API,ConstraintNotSatisfiedError { constraintName: "height" }
.
I Cannot find any option in the API description or on the web that describes how to use the webcam in portrait mode.
In my browser application (with AngularJS
) I am making a connection to the webcam via the HTML5 getUserMedia API
. But for some reason the output stream is always in landscape mode
and not in portrait mode
. So I've tried a few things, but I cannot figure out how to get it into portrait mode. Any idea's?
Specs:
AngularJS: 1.6.5
IMac: 27" - MacOS high Sierra
Chrome: 61.0.3163.100 (64-bit)
My code
private static readonly videoOptions = {
mandatory: {
minWidth: 1080,
minHeight: 1920
}
};
private startCamera(): void {
navigator.mediaDevices.getUserMedia({video: MWWebcamController.videoOptions, audio: false})
.then((stream: MediaStream) => {
this.webcam = new WebcamStream(window.URL.createObjectURL(stream), stream);
})
.catch((exception) => {
console.error("Could not load the stream. due to: ", exception);
});
}
I've tried
- Rotating the video via CSS. This kind of works, but the stream won't be rotated with it.
- Settings the
mendatory
property on the videoOptions to{ height:1920, width: 1080 }
, but this results in an error from the API,ConstraintNotSatisfiedError { constraintName: "height" }
.
I Cannot find any option in the API description or on the web that describes how to use the webcam in portrait mode.
Share Improve this question asked Oct 20, 2017 at 11:36 Mr.wiseguyMr.wiseguy 4,25211 gold badges39 silver badges68 bronze badges1 Answer
Reset to default 9The iMac (and all desktop devices) has a landscape positioned webcam image sensor so you'll only be able to capture at the sensor's max resolution in landscape mode (e.g. 1920x1080).
Chrome crops and scales the video ing from the webcam to fulfill your constraints so you should get a portrait image if you use a resolution where the height does not go over the sensor's max height (e.g. 270x480 which is 16 times smaller than 1080x1980)
var constraints = {
audio: false,
video: {
width: { min: 270, max: 270 },
height: { min: 480, max: 480},
},
};
You can use the getUserMedia camera resolution finder to find the (landscape) resolutions supported by your webcam & browser bo.
本文标签: javascripthtml5 getUserMedia() portrait modeStack Overflow
版权声明:本文标题:javascript - html5 getUserMedia() portrait mode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741430815a2378346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论