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.
To get the file size, we will use filesize() function. The filesize() function returns the size of a file in bytes. This function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.
Here is simple example: $SongPath = 'http://localhost/PE/uploads/pe_discussion/videos/Wildlife.wmv'; if($SongPath){ $filename = tempnam('/tmp','getid3'); if (file_put_contents($filename, file_get_contents($SongPath, false, null, 0, 300000))) { if (require_once('getid3/getid3.
For example, we can implement simple codes below to get the duration of a video file.. $thisVideoFile = new ffmpeg_movie("video. ext"); echo $thisVideoFile->getDuration(); The code above is that all we need to get and display duration of the video.
Show activity on this post. $videoFile = 'addicted. mp4'; $duration = $ffprobe ->streams($videoFile) ->videos() ->first() ->get('duration'); echo $duration; Why I can't receive video information? @VipulJethva you probably need absolute path to the video file.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With