PHP将sec转换为min

时间:2016-02-16 06:46:39

标签: php ffmpeg

我有这个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 . "%";

}

1 个答案:

答案 0 :(得分:0)

 executor.execute(()->    {
    try {
      while(true)
      {
          EventQueue eventQueue = vm.eventQueue();
          EventSet eventSet = eventQueue.remove();
          EventIterator eventIterator = eventSet.eventIterator();
          if (eventIterator.hasNext()) {
            Event event = eventIterator.next();
            if(event instanceof ClassPrepareEvent) {
              ClassPrepareEvent evt = (ClassPrepareEvent) event;
              ClassType classType = (ClassType) evt.referenceType();
              List<Location> locations = referenceType.locationsOfLine(55);
              Location locationForBreakpoint = locations.get(0);

              vm.resume();
            }
          }
        }
    } catch (InterruptedException | AbsentInformationException | IncompatibleThreadStateException e) {
      e.printStackTrace();
    }
  }