-
Notifications
You must be signed in to change notification settings - Fork 5
/
progress.php
52 lines (46 loc) · 1.29 KB
/
progress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* FFmpeg Terminal Progress
* @Author: Pedram Asbaghi
* @Email: [email protected]
* @Date: 03/2019
*/
require 'config.php';
$currentLog = LOG_PATH;
$getContent = file_get_contents($currentLog);
preg_match("/Duration: (.*?), start:/ms", $getContent, $matches);
if(!empty($rawDuration = $matches[1]))
$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;
preg_match_all("/time=(.*?) bitrate/", $getContent, $matches);
$rawTime = array_pop($matches);
if (is_array($rawTime)){$rawTime = array_pop($rawTime);}
$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;
//progress prec..
$progress = round(($time/$duration) * 100);
if($progress > 98)
{
$results = 'done';
}
elseif(strpos($getContent, 'Qavg') !== false)
{
$results = 'done';
}
elseif(strpos($getContent, 'kb/s:') !== false)
{
$results = 'done';
}
elseif(strpos($getContent, 'does not contain any stream') !== false)
{
$results = 'error_audio';
}
else
{
$results = $progress;
}
echo json_encode(array('progress' => $results));