Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect video file duration in minutes with PHP?

Tags:

php

video

I am trying to detect the duration of any video file before it is uploaded with PHP
so if it is less than one minute for example I will refuse uploading it.
if it is not possible , how can I do it after uploading the video ??

like image 543
Evan Lévesque Avatar asked Apr 06 '12 12:04

Evan Lévesque


1 Answers

You can get video duration with ffmpeg or getID3

Example

$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 />");

Or

 ob_start();
 passthru("ffmpeg -i working_copy.flv  2>&1");
 $duration = ob_get_contents();
 $full = ob_get_contents();
 ob_end_clean();
 $search = "/duration.*?([0-9]{1,})/";
 print_r($duration);
 $duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
 print_r('<pre>');
 print_r($matches[1][0]);
 print_r($full);

Please see

http://getid3.sourceforge.net/

http://ffmpeg.org/

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

get flv video length

Thanks

:D

like image 58
Baba Avatar answered Sep 21 '22 15:09

Baba