Reputation: 361
I'm trying to learn how to develop webRTC applications and I would like to know whether you can get a camera's aspect ratio... (I don't know if it helps, but I'm using webrtc.io, but -if it's better- I could stop using it)
Upvotes: 7
Views: 6818
Reputation: 623
From MDN, you can get the current video stream's aspectRatio
from MediaTrackSettings
by calling:
stream.getVideoTracks()[0].getSettings().aspectRatio
Upvotes: 4
Reputation: 20248
Since you are accessing the camera through a <video>
-element, you should use the videoWidth
and videoHeight
attributes to calculate the aspect ratio. These values reflect the actual dimensions of the source mediastream and can differ from the width
and height
attributes of the <video>
element as rendered on the page.
This approach seems to work well in Chrome and Firefox Nightly.
Upvotes: 2
Reputation: 6982
Right now, the best assumption is square pixels, and thus width/height is a good approximation.
There's discussion in the Media Capture Task Force about capabilities, but the actual aspect ratio isn't available currently IIRC.
You should ask on the public-media-capture list at w3.org
Upvotes: 0