Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 312
Chandan Avatar asked Jan 31 '11 04:01

Chandan


People also ask

How to get video file size in php?

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.

How to get duration From video url in php?

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.

How can I get video duration in PHP without ffmpeg?

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.

How can I get video duration in PHP with ffmpeg?

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.


1 Answers

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/

like image 168
aendra Avatar answered Sep 20 '22 12:09

aendra