rondog Posted May 2, 2008 Share Posted May 2, 2008 I have a series of videos and I am pulling the duration of the FLVs using FFMPEG. The problem is, it outputs it in seconds, so rather than 1:12 it says 72. Can I get help making a function to convert seconds to minutes? This is what I am doing to get the duration: function getDur($src) { $mov = new ffmpeg_movie($src,false); $duration = $mov->getDuration(); $duration = round($duration); return $duration; } while($row = mysql_fetch_array($videoquery)) { $file = $row['filename']; $duration = getDur("videos/".$file); array_push($viddur,$duration); array_push($vids,$file); } then my $viddur array contains the video file durations in seconds. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/ Share on other sites More sharing options...
effigy Posted May 2, 2008 Share Posted May 2, 2008 <pre> <?php $secs = 72; echo (int)($secs/60) . ':' . $secs % 60; ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532011 Share on other sites More sharing options...
rondog Posted May 2, 2008 Author Share Posted May 2, 2008 well that works for the most part. If you do anything between 60-69 it does: sec = 61 outputs 1:1 Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532015 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 % is the modulus operator...you might know it as the "remainder" from elementary school division. Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532019 Share on other sites More sharing options...
Rohan Shenoy Posted May 2, 2008 Share Posted May 2, 2008 <?php $duration="130";// in seconds $min=ceil($duration/60)-1; $sec=$duration%60; if(strlen($sec)=="1") { $sec="0".$sec; } echo "Duration: $min:$sec"; //outputs 2:01 ?> Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532020 Share on other sites More sharing options...
rondog Posted May 2, 2008 Author Share Posted May 2, 2008 @dw: i modified my post..it kind of works lol @roh: im going to try yours right now! Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532022 Share on other sites More sharing options...
rondog Posted May 2, 2008 Author Share Posted May 2, 2008 ok roh, your method works except for 60 seconds..I get 0:00 ? Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532027 Share on other sites More sharing options...
Rohan Shenoy Posted May 2, 2008 Share Posted May 2, 2008 Oh sorry about that: here the moded code: <?php $duration="60"; if($duration=="60") { $min="1"; } else { $min=ceil($duration/60)-1; } $sec=$duration%60; if(strlen($sec)=="1") { $sec="0".$sec; } echo "Duration: $min:$sec"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532031 Share on other sites More sharing options...
rondog Posted May 2, 2008 Author Share Posted May 2, 2008 nice work man..works like a charm! Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532043 Share on other sites More sharing options...
Rohan Shenoy Posted May 2, 2008 Share Posted May 2, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532046 Share on other sites More sharing options...
Barand Posted May 2, 2008 Share Posted May 2, 2008 <?php $secs = 65; $mins = sprintf('%d:%02d', $secs/60, $secs % 60); echo $mins; // 1:05 ?> Quote Link to comment https://forums.phpfreaks.com/topic/103921-solved-convert-seconds-to-minutes/#findComment-532165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.