Monday, March 23, 2009

video duration using ffmped

you can get the video duration in second using ffmped following code block will show you how to do it.

function getDuration()
{
//this is the path of the video that you want to get the file duration
$filepath = $this->baseDir."/".$this->video_name;
ob_start();
passthru("$this->ffmpeg -i \"". $filepath . "\" 2>&1");
$duration = ob_get_contents();

ob_end_clean();
preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];
$duration_array = split(':', $duration);
$duration = $duration_array[0] * 3600 + $duration_array[1] * 60 + $duration_array[2];
return $duration;
}

this will return the duration in second

No comments: