Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webrtc - get webcam's aspect ratio

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)

like image 522
goldstein Avatar asked Oct 06 '22 21:10

goldstein


2 Answers

From MDN, you can get the current video stream's aspectRatio from MediaTrackSettings by calling:

stream.getVideoTracks()[0].getSettings().aspectRatio
like image 159
Alex Avatar answered Oct 13 '22 11:10

Alex


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.

like image 25
le_m Avatar answered Oct 13 '22 10:10

le_m