Getting video duration using ffmpeg, php function

I have FFMpeg installed and I know it is functional, but I am trying to get duration time from FLV video via PHP, but when I use this code:

MbmGetFLVDuration ($ file) {

/*  
* Determine video duration with ffmpeg   
* ffmpeg should be installed on your server.  
*/  

//$time = 00:00:00.000 format   
$ffmpeg = "../ffmpeg/ffmpeg";

$time =  exec("$ffmpeg -i $file 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");   

$duration = explode(":",$time);   
$duration_in_seconds = $duration[0]*3600 + $duration[1]*60+ round($duration[2]);   

return $duration_in_seconds;   

      

}

and

$ duration = mbmGetFLVDuration (' http://www.videoaddsite.com/videos/intro.flv '); echo $ duration;

I get output 220. This video is 3:40. Can anyone help me on what I am doing wrong, or if there is something else I can use?

+3


source to share


2 answers


I don't see the problem. 220 seconds - 3:40.

To get minutes and seconds use this conversion:



<?php
$seconds = 220;
$minutes = $seconds/60;
$real_minutes = floor($minutes);
$real_seconds = round(($minutes-$real_minutes)*60);
?>

      

$real_minutes

will be 3 and $real_seconds

will be 40.

+3


source


$ffmpeg = "../ffmpeg/ffmpeg";

$time = exec("$ffmpeg -i $file 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");   

$duration = explode(":", $time);   
$duration_in_seconds = ($duration[0] * 3600) + ($duration[1] * 60) + round($duration[2]);   

return $duration_in_seconds;   

      



0


source







All Articles