Jump to content

[SOLVED] getDuration() problem


rondog

Recommended Posts

I am getting the duration of an FLV through FFMPEG/FFMPEG PHP.

 

I made a function that returns the duration in minutes, however, I have noticed my clips that land right on 2:00, show up as 1:00. I cant figure out why. If its 2:20, it shows up properly as 2:20..It just seems to be a problem when it lands on the 0th second of a minute. Can anyone maybe shed some light?

<?php
//the duration function
function getDur($src) {
	$mov = new ffmpeg_movie($src,false);
	$duration = $mov->getDuration();
	$duration = round($duration);

	if($duration == "60")	{
		$min = "1";
	} else {
		$min = ceil($duration / 60) - 1;
	}
	$sec = $duration % 60;
	if(strlen($sec) == "1") {
		$sec = "0".$sec;
	}
	$duration = "$min:$sec";
	return $duration;
}

//where I call the duration
while($row = mysql_fetch_array($result)) {
	$duration = getDur("videos/".$row['filename']);
	echo $duration;
} 

//etc etc...
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/113777-solved-getduration-problem/
Share on other sites

I found my old post from this and barrand posted a solution after I checked topic solved and I never saw it. This one seems to be working out so far:

<?php
function getDur($src) {
	$mov = new ffmpeg_movie($src,false);
	$duration = $mov->getDuration();
	$duration = round($duration);
   		$mins = sprintf('%d:%02d', $duration/60, $duration % 60); 
	return $mins;                                
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.