Extract information from a video at the time of upload

1

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

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

Brief example:

    
asked by anonymous 01.11.2014 / 13:56

2 answers

3

In javascript this is very limited for security reasons.

The size I know is possible through 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: link

In PHP I found this answer which suggests a external library getID3 that supports different formats. Taking 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 />");
    
01.11.2014 / 14:47
-1

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

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

or

$new_var = $_FILES["upload"];
echo $new_var["size"];
    
01.11.2014 / 20:40