-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-video-duration.php
44 lines (35 loc) · 1.13 KB
/
get-video-duration.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
<?php
include "conn.php";
$supported_ext = array('flv', 'mp4');
$path = './video/';
if ($handle = opendir($path)) {
echo "Entries:<br>";
while (false !== ($file = readdir($handle))) {
if (!is_dir($path.$file)){
$splitted = explode('.', $file);
$ext = strtolower($splitted[count($splitted)-1]);
if (in_array($ext, $supported_ext)) {
//$files[] = $file;
echo "$file: ";
ob_start();
passthru(FFMPEG_PATH . " -i \"". $path.$file . "\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();
preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];
echo "$duration ";
$duration_array = split(':', $duration);
$duration = $duration_array[0] * 3600 + $duration_array[1] * 60 + $duration_array[2];
$duration = floor($duration);
echo "$duration<br>";
//if (!$mysqli->query("UPDATE videos SET duration='$duration' WHERE filename='$file'"))
// echo "query error";
//if ($mysqli->affected_rows != 1)
// echo "query error";
}
}
}
closedir($handle);
}
$mysqli->close();
?>