是否可以检测 HTML5 视频元素的纵横比?
我知道视频会缩小以适合 <video>
元素的尺寸,但我想检测源视频的纵横比。
这样你就可以删除任何黑条。
抱歉,我在其他任何地方都没有看到这个问题的答案。
最佳答案
从另一个 StackOverflow 答案粘贴: 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
然后您可以通过将宽度除以高度来计算纵横比。
关于html - 检测纵横比 - HTML5 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14904623/