Obtaining video sizes before downloading, on the client side

I have a form for uploading videos. The user clicks on the view and select the file. How can I get the video size at the moment the user selects a file (before the file is even uploaded to the server). Obviously, this should be something on the client side, possibly with javascript / jquery or flash / flex (preferably js // jquery), but can any of them do this?

+3
source share
4 answers

Unfortunately, the short answer is that you cannot - you need access to scan the contents of the file using javascript, which is not allowed. Worse, even if you somehow read the file, you will need to implement a whole set of codecs in JS to read the header information.

Mark this as impossible.

+2
source

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

Once the file is read, you can parse the headers. As far as I know, no one has ever done this in javascript.

+2
source

: no

: () :

jQuery,

0

This is a very old question, but now you can find out the video sizes on the client side before downloading.

Refer to this question: HTML5 Video Dimensions

Code example:

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

Source: https://habr.com/ru/post/1790683/


All Articles