ffmpeg php 进度,ffmpeg进度条 – PHP中的编码百分比

好的,我找到了我需要的东西 – 希望这对其他人也有帮助!

首先,您希望将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秒:)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值