我想要FFmpeg編碼的進度條。這是我用來獲取編碼過程的百分比值的代碼。FFMPEG(2.5.7)來自PHP的進度條
<?php
$content = @file_get_contents("with-logo/output.txt");
//echo $content;
if($content) {
preg_match("/Duration: (.*?), start:/", $content, $matches);
$rawDuration = $matches[1];
$ar = array_reverse(explode(":", $rawDuration));
$duration = floatval($ar[0]);
//echo $duration;
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 . "<br>";
echo "Current Time: " . $time . "<br>";
echo "Progress: " . $progress . "%";
}
?>
這裏是相關的日誌行表單我的FFMPEG日誌文件爲更好的理解。
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 11 fps=0.0 q=0.0 size= 0kB time=00:00:00.41 bitrate= 0.9kbits/s
frame= 22 fps= 21 q=0.0 size= 0kB time=00:00:00.85 bitrate= 0.4kbits/s
frame= 33 fps= 21 q=0.0 size= 0kB time=00:00:01.30 bitrate= 0.3kbits/s
frame= 43 fps= 20 q=0.0 size= 0kB time=00:00:01.69 bitrate= 0.2kbits/s
這個代碼不爲Duration
返回值,並作爲這個我收到PHP警告和代碼的結果是不是計算的當前百分比。
這裏是PHP的警告,對此我getting-
PHP Warning: Division by zero in /var/www/html/mm/progressbar.php
我想我們還可以計算從time
的百分比,但我不知道,我怎麼能使其工作?
或任何幫助解決持續時間的問題。
感謝您的幫助!
Hi @Robbbie! 你已經建議的第二個選項,我會盡快嘗試,但現在爲了獲得持續時間的值,我手動在你建議'ffmpeg /tmp/out.mp4 2>&1 | grep「持續時間」'。我沒有得到任何反饋,它只是沒有任何迴應。 – kunal
您的指示缺少-i? – Robbie
哦!我很抱歉,我只是錯過了,你搖滾 謝謝@羅比 – kunal