Detect aspect ratio - HTML5 video
Asked Answered
C

1

8

Is it possible to detect the aspect ratio of an HTML5 video element?

I know the video will just shrink to fit in the <video> element's dimensions, but I want to detect the aspect ratio of the source video.

That way you could remove any black bars.

Sorry I don't see this answered anywhere else.

Cheesecloth answered 15/2, 2013 at 22:43 Comment(1)
Possible duplicate of HTML5 Video DimensionsTrinitrophenol
T
25

Pasting from another StackOverflow answer: https://mcmap.net/q/166988/-html5-video-dimensions

<video id="foo" src="foo.mp4"></video>

var vid = document.getElementById("foo");
vid.videoHeight; // returns the intrinsic height of the video
vid.videoWidth; // returns the intrinsic width of the video

Source (HTML5 spec): http://www.w3.org/TR/html5/video.html#video

You can then calculate the aspect ratio by dividing the width by the height.

Torchbearer answered 15/2, 2013 at 22:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.