Extract information from a video at the time of upload

Asked

Viewed 797 times

2

Uploading any video is the easy part, but I would like to explore this moment of uploading more. I would like to extract some information from the video at the time of uploading. This information would be the time the video has and the amount of MB of it. And I would also like at the time of the upload this extracted information to automatically fill in the inputs related to this information.

What I really want is to extract the information, be it in php, jquery or any other kind of viable medium.

Brief example :

inserir a descrição da imagem aqui

  • It would be good if you showed the method you are using to upload.

  • At the moment I can say that there is no method, I’m just using a little PHP to grab the file and transfer the video to a folder. You want me to post php code?

  • Ivan in Javascript is very limited. Almost everything is forbidden/blocked for security reasons. I think you’ll have to do it via PHP, and that means "after the upload".

  • @Sergio, it may also be after the upload, but how can I extract this information from the video with php?

  • 2

    In this case I suggest to edit the question, join this possibility and join the PHP tag as well

2 answers

4


Javascript this is very limited for safety reasons.

The size I know is possible through the this.files[0].size and the name, through this.files[0].name used an Event Handler in jQuery. Then to format to be noticeable you can use a function like this:

function humanFileSize(bytes, si) {
    var thresh = si ? 1000 : 1024;
    if(bytes < thresh) return bytes + ' B';
    var units = si ? ['kB','MB','GB','TB','PB','EB','ZB','YB'] : ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
    var u = -1;
    do {
        bytes /= thresh;
        ++u;
    } while(bytes >= thresh);
    return bytes.toFixed(1)+' '+units[u];
};

Example: http://jsfiddle.net/16jv4r89/1/

In PHP found this answer which suggests a external library getID3 which supports different formats. Having a look at the page supports the most common formats.

So in PHP it would be:

$getID3 = new getID3;
$file = $getID3->analyze($filename);
echo("Duration: ".$file['playtime_string'].
" / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
" / Filesize: ".$file['filesize']." bytes<br />");
  • 1

    U’re fast, man :) I found the same answer there in OS... . . . . @Ivan, I was searching and there is interesting material here on the site, like Upload a file with ajax; had another one that was to capture images before upload but I’m not finding it.

-1

You can always use print_r($_FILES["upload"]) to download the file properties and then use what you want ex get the size you have

echo $_FILES["upload"]["size"];

or

$new_var = $_FILES["upload"];
echo $new_var["size"];
  • This is only available after the file has been uploaded to the server. The question is on how to get the length or size of the video file before that.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.