使用jQuery确定视频文件大小 [英] Using jQuery to determine video file size

查看:81
本文介绍了使用jQuery确定视频文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用videojs播放各种尺寸的html5视频。是否可以使用jQuery(或其他脚本语言)检测视频文件的高度/宽度,以便我可以将这些动态输入到嵌入代码中?

I am using videojs to play html5 videos, of varying dimensions. Is it possible to detect the height/width of a video file using jQuery (or another scripting language for that matter) so that I can dynamically input these into the embed code?

谢谢!

推荐答案

我担心这不太可能。为了让浏览器能够确定视频的大小,它必须先加载它。

I'm afraid that's not quite possible. For the browser to be able to determine the size of the video, it has to load it first.

一个解决方案可能是,假设这甚至可以工作,加载视频首先没有指定高度和宽度,但使用CSS隐藏视频,计算尺寸,销毁视频并使用正确的大小再次加载它。这将是非常低效的。

One solution could be, assuming that this would even work, to load the video first without specifying a height and width but using CSS to hide the video, calculate the dimensions, destroy the video and load it again on click using the right size. This would be incredibly inefficient.

或者,您可以创建一个服务器端脚本(PHP / ASP / ...)来读取视频文件,检测高度和最初保存内容时的宽度,并将高度和宽度保存到数据库。然后,您可以在每个页面视图上从数据库中读取高度和宽度。虽然您可以在每个请求上制作这样的脚本来读取视频文件,但这样效率会很低,并且会增加生成页面所需的时间。

Alternatively, you could make a server-side script (PHP/ASP/...) that reads the video file, detects the height and width when you content is originally saved and save the height and width to a database. You would then be able to read the height and width from the database on every page view. While you could make such a script read the video file on every request instead, this would be inefficient and would increase the time required to generate the page.

如果你是使用PHP,我强烈建议您查看 ffmpeg-php ,这是一个免费的开源库您可以用来解析几种类型的视频文件。

If you're using PHP, I'd highly recommend you look at ffmpeg-php, a free and open-source library you can use to parse several type of videos files.

另一个想法:另一个解决方案可能是不指定嵌入的高度和宽度代码,让浏览器自己调整视频大小。然后,您可以调整灯箱的大小以修复视频容器。许多灯箱插件都有可以挂钩的事件。

Another thought: Another solution could be to not specify the height and width in the embed code and let the browser size the video on it's own. You could then resize the lightbox to fix the video container. Many lightbox plugins have events that you can hook into.

这篇关于使用jQuery确定视频文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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