栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

ffmpeg进度栏-PHP中的编码百分比

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ffmpeg进度栏-PHP中的编码百分比

好的,我已经找到了我所需要的-希望这对其他人也有帮助!

首先,您希望将ffmpeg数据输出到服务器上的文本文件。

ffmpeg -i path/to/input.mov -vprec videoprec -aprec audioprec 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 enpred    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 . "%";}

这将输出剩余时间的百分比。

您可以将其作为回传到页面的唯一文本,并且可以在另一个页面上使用jQuery执行AJAX请求,以获取该文本并将其输出到div中,例如,在每个页面上更新10秒



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/443189.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号