How to get video duration, dimension and size in PHP?

Chandan picture Chandan · Jan 31, 2011 · Viewed 111.4k times · Source

I want to know how to get the duration, dimension and size of uploaded video file in PHP. The file can be in any video format.

Answer

aendrew picture aendrew · Jan 31, 2011

getID3 supports video formats. See: http://getid3.sourceforge.net/

Edit: So, in code format, that'd be like:

include_once('pathto/getid3.php');
$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 />");

Note: You must include the getID3 classes before this will work! See the above link.

Edit: If you have the ability to modify the PHP installation on your server, a PHP extension for this purpose is ffmpeg-php. See: http://ffmpeg-php.sourceforge.net/