Repository navigation
Expand file tree
/
Copy pathffprobe.php
More file actions
55 lines (43 loc) · 1.44 KB
/
Copy pathffprobe.php
File metadata and controls
55 lines (43 loc) · 1.44 KB
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
53
54
55
<?php
/*
* ffprobe class helper for ffmpeg 0.9+ (JSON support)
* Written by Paulo Freitas <me@paulofreitas.me> under CC BY-SA 3.0 license
*/
class ffprobe
{
public function __construct($filename, $prettify = false)
{
if (!file_exists($filename)) {
throw new Exception(sprintf('File not exists: %s', $filename));
}
$this->__metadata = $this->__probe($filename, $prettify);
}
private function __probe($filename, $prettify)
{
// Start time
$init = microtime(true);
// Default options
$options = '-loglevel quiet -show_format -show_streams -print_format json';
if ($prettify) {
$options .= ' -pretty';
}
// Avoid escapeshellarg() issues with UTF-8 filenames
setlocale(LC_CTYPE, 'en_US.UTF-8');
// Run the ffprobe, save the JSON output then decode
$json = json_decode(shell_exec(sprintf('ffprobe %s %s', $options,
escapeshellarg($filename))));
if (!isset($json->format)) {
throw new Exception('Unsupported file type');
}
// Save parse time (milliseconds)
$this->parse_time = round((microtime(true) - $init) * 1000);
return $json;
}
public function __get($key)
{
if (isset($this->__metadata->$key)) {
return $this->__metadata->$key;
}
throw new Exception(sprintf('Undefined property: %s', $key));
}
}