gpt4 book ai didi

PHP将秒转换为分钟

转载 作者:行者123 更新时间:2023-12-04 23:28:00 26 4
gpt4 key购买 nike

我有这个 php 代码可以检索使用 FFMPEG 转换视频所花费的时间。但是输出以秒为单位。我的数学让我失望了,我不能让它在几分钟而不是几秒钟内显示出来。

将不胜感激任何帮助。

            $content = @file_get_contents('logfile.txt');

if($content){
//get duration of source
preg_match("/Duration: (.*?), start:/", $content, $matches);

$rawDuration = $matches[1];

//rawDuration is in 00:00:00.00 format. This converts it to seconds.
$ar = array_reverse(explode(":", $rawDuration));
$duration = floatval($ar[0]);
if (!empty($ar[1])) $duration += intval($ar[1]) * 60 ;
if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60 * 60;

//get the time in the file that is already encoded
preg_match_all("/time=(.*?) bitrate/", $content, $matches);

$rawTime = array_pop($matches);

//this is needed if there is more than one match
if (is_array($rawTime)){$rawTime = array_pop($rawTime);}

//rawTime is in 00:00:00.00 format. This converts it to seconds.
$ar = array_reverse(explode(":", $rawTime));
$time = floatval($ar[0]);
if (!empty($ar[1])) $time += intval($ar[1]) * 60;
if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;

//calculate the progress
$progress = round(($time/$duration) * 100);

echo "Duration: " . $duration . "<br>";
echo "Current Time: " . $time . "<br>";
echo "Progress: " . $progress . "%";

}

最佳答案

<?
$seconds = "150";
$minutes = floor($seconds/60);
$secondsleft = $seconds%60;
if($minutes<10)
$minutes = "0" . $minutes;
if($secondsleft<10)
$secondsleft = "0" . $secondsleft;
echo "$minutes:$secondsleft minutes";
?>

关于PHP将秒转换为分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35425577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com