开发者

How do I convert time in the format '00:04:13.67' to seconds?

basically i have a variable that holds a time value, in this format '00:04:13.67'. I need a short and simple php function to convert that to seconds.

What i'm ultimately tring to do is get the duration of videos i have stored on a amazon cloud front using ffmpeg, but ffmpeg returns duration in unwanted format "hours:minutes:seconds.decimals" i need time in seconds.

here's my c开发者_如何学Code if any has a simpler or cleaner solution i'd appreciate it very much

$videofile="http://123abc.cloudfront.net/test.flv";
ob_start();
passthru("/usr/bin/ffmpeg -i \"{$videofile}\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();

$duration=preg_match('/Duration: (.*?),/', $duration, $matches, PREG_OFFSET_CAPTURE, 3);
//TEST ECHO
echo $matches[1][0];


<?php
$hours = (int) substr($timeStr, 0, 2);
$mins = (int) substr($timeStr, 3, 2) + $hours * 60;
$secs = (int) substr($timeStr, 6, 2) + $mins * 60;
$secs += ((int) substr($timeStr, 9, 2)) / 100;
?>

$timeStr is your time string. That should give you seconds (as float). Wrap it up in a function if you will.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜