小编典典
好的,我已经找到了我所需要的-希望这对其他人也有帮助!
首先,您希望将ffmpeg数据输出到服务器上的文本文件。
ffmpeg -i path/to/input.mov -vcodec videocodec -acodec audiocodec path/to/output.flv 1> block.txt 2>&1
因此,ffmpeg的输出为block.txt。 现在在PHP中,让我们开始吧!
$content = @file_get_contents('../block.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;
//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 . "
";
echo "Current Time: " . $time . "
";
echo "Progress: " . $progress . "%";
}
这将输出剩余时间的百分比。
您可以将其作为回传到页面的唯一文本,并且可以在另一个页面上使用jQuery执行AJAX请求,以获取该文本并将其输出到div中,例如,在每个页面上更新10秒
2020-05-29