检测宽高比 - HTML5视频 [英] Detect aspect ratio - HTML5 video

查看:350
本文介绍了检测宽高比 - HTML5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测HTML5视频元素的宽高比?

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.

推荐答案

从另一个StackOverflow回答粘贴:
https://stackoverflow.com/a/4129189/1353189

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

来源(HTML5规范): http://www.w3.org/TR/html5/video.html#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.

这篇关于检测宽高比 - HTML5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆