run(); $process->wait(); if (!$process->isSuccessful()) { return false; } $xml = simplexml_load_string($process->getOutput()); $json = json_encode($xml); return json_decode($json, true); } /** * @param $name * @param $array * @param bool $default * @return bool */ public function getAttribute($name, $array, $default = false){ foreach ($array as $key => $item) { if ($key === $name) { return $item; } else { if (is_array($item)) { $r = $this->getAttribute($name, $item, $default); if($r !== false) return $r; } } } return false; } /** * transform mediainfo duration to timecode or to ms if $toMs is set to true * * @param $duration * @param bool $toMs * @return int|mixed|string */ public function durationToTime($duration, $toMs = false){ $output = array(); $strTime = ""; $timMs = 0; $ext = array('h','mn','s','ms'); $relative = array('h' => 3600000,'mn' => 60000,'s' => 1000,'ms' => 1); foreach($ext as $t){ preg_match("/([0-9]{1,2}".$t.")/i", $duration, $output_array); $output[$t] = 0; if(isset($output_array[1])){ $tim = str_replace($t,'',$output_array[1]); $output[$t] = (int)$tim; if(strlen($tim) <= 1) $strTime .= "0"; $strTime .= $tim; //to ms $timMs += ($output[$t] * $relative[$t]); } else $strTime .= "00"; if($t != 'ms') $strTime .= ":"; } if(!$toMs) return $strTime; return $timMs; } /** * @param $milsec * @param bool $withMs * @return string */ public function convertMsToTimecode($milsec, $withMs = false) { $init = $milsec/1000; $init = number_format($init, 2); $secs = floor($init); $milli = (int) (($init - $secs) * 1000); $milli = str_pad($milli, 2, '0', STR_PAD_LEFT); $hours = ($secs / 3600); $minutes = (($secs / 60) % 60); $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); $seconds = $secs % 60; $seconds = str_pad($seconds, 2, '0', STR_PAD_LEFT); if ($hours > 1) { $hours = str_pad($hours, 2, '0', STR_PAD_LEFT); } else { $hours = '00'; } if($milli <= 9) $milli = "0".$milli; $Time = "$hours:$minutes:$seconds"; if($withMs) $Time .= ":".$milli; return $Time; } }