getting video dimensions before upload, client-side

流过昼夜 提交于 2019-12-12 13:52:20

问题


I have an upload form for an video. The user clicks browse and selects a file. How can I get the video dimensions the moment the user selects the file (before the file is even uploaded to the server). It obviously has to be something client-side with maybe javascript/jquery or flash/flex (prefer js//jquery though), but can either of them do this?


回答1:


Unfortunately, the short answer is you can't - You'd need access to scan the file contents using javascript which isn't allowed. Worse than that, even if you could read the file somehow, you'd need to implement a whole host of codecs in JS just to read the header information.

Mark this one as not possible




回答2:


In theory you should be able to use the FileReader API - https://developer.mozilla.org/en/DOM/FileReader

Once the file has been read, you can parse out the headers. As far as I know, nobody has ever done this in javascript.




回答3:


If dimensions is resolution: no

If dimensions is file-size: (now) yes:

Using jQuery, Restricting File Size Before Uploading




回答4:


This is a very old question but now it's possible to know video dimensions on client side before upload.

Refer to this question: HTML5 Video Dimensions

Example code:

var v = document.getElementById("myVideo");
v.addEventListener( "loadedmetadata", function (e) {
    var width = this.videoWidth,
        height = this.videoHeight;
}, false );


来源:https://stackoverflow.com/questions/4932723/getting-video-dimensions-before-upload-client-side

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