Detect aspect ratio - HTML5 video

浪尽此生 提交于 2019-12-10 08:25:55

问题


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.


回答1:


Pasting from another StackOverflow answer: https://stackoverflow.com/a/4129189/1353189

<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.



来源:https://stackoverflow.com/questions/14904623/detect-aspect-ratio-html5-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!