首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >php中的FFMPEG进度条

php中的FFMPEG进度条
EN

Stack Overflow用户
提问于 2016-01-19 09:45:03
回答 1查看 1.9K关注 0票数 1

我正在使用ffmpeg来转换一个视频文件,大文件需要很长时间才能编码。我想显示带有剩余百分比/时间的进度条

我看到并尝试了这个example,但由于某种原因,进度条没有显示。

Html表单

代码语言:javascript
代码运行次数:0
运行
复制
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file"><span></span></label>
<input type="file" name="file" id="file" /> 
<br/>
Please enter video title:
<br/>
<input type"text" name="videoTitle" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

<div id="myDiv" name="myDiv" title="test">
        <h5>Encoding percentage</h5>
        <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
                <script>
                $(document).ready(function(){
                setInterval(function(){
                $("#screen").load('progress.php')
                }, 10000);
                });
                </script>
        </div>

upload.php ffmpeg脚本

代码语言:javascript
代码运行次数:0
运行
复制
shell_exec("C:\\ffmpeg\\bin\\ffmpeg.exe -y -i ".$target_file." -c:v libx264 -s:v 854x480 -c:a copy \"{$newFileName}\" > logfile.txt 2>&1"); // script to encode video

Progress.php

代码语言:javascript
代码运行次数:0
运行
复制
$content = @file_get_contents('blocks.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 . "<br>";
            echo "Current Time: " . $time . "<br>";
            echo "Progress: " . $progress . "%";

}

?>
EN

回答 1

Stack Overflow用户

发布于 2017-03-16 19:38:48

FFMpeg的最新版本中,要创建日志文件,必须使用选项-vstats_file

因此,您必须将编码视频脚本更改为:

代码语言:javascript
代码运行次数:0
运行
复制
shell_exec("C:\\ffmpeg\\bin\\ffmpeg.exe -y -i ".$target_file." -c:v libx264 -s:v 854x480 -c:a copy \"{$newFileName}\" -vstats_file PATH_TO_YOUR\logfile.txt"); // script to encode video
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34867202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档