-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFmpegCustomOutputProvider.php
executable file
·61 lines (51 loc) · 1.92 KB
/
FFmpegCustomOutputProvider.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
53
54
55
56
57
58
59
60
61
<?php
/**
* FFmpegOutputProvider ffmpeg provider implementation
*
* @author char0n (Vladimír Gorej, [email protected])
* @package FFmpegPHP
* @subpackage provider
* @license New BSD
* @version 2.6
*/
class FFmpegCustomOutputProvider extends AbstractOutputProvider {
protected static $EX_CODE_NO_FFMPEG = 334560;
/**
* Constructor
*
* @param string $ffmpegBinary path to ffmpeg executable
* @param boolean $persistent persistent functionality on/off
*/
public function __construct($ffmpegBinary = 'ffmpeg', $persistent = false) {
parent::__construct($ffmpegBinary, $persistent);
}
/**
* Getting parsable output from ffmpeg binary
*
* @return string
* @throws Exception
*/
public function getOutput() {
// Persistent opening
if ($this->persistent == true && array_key_exists(get_class($this).$this->binary.$this->movieFile, self::$persistentBuffer)) {
return self::$persistentBuffer[get_class($this).$this->binary.$this->movieFile];
}
// File doesn't exist
if (@file_get_contents($this->movieFile, false, null, 0, 0) === false) {
throw new Exception('Movie file not found', self::$EX_CODE_FILE_NOT_FOUND);
}
// Get information about file from ffmpeg
$output = array();
exec($this->binary.' -i '.escapeshellarg($this->movieFile).' 2>&1', $output, $retVar);
$output = join(PHP_EOL, $output);
// ffmpeg installed
if (!preg_match('/FFmpeg version/i', $output)) {
throw new Exception('FFmpeg is not installed on host server', self::$EX_CODE_NO_FFMPEG);
}
// Storing persistent opening
if ($this->persistent == true) {
self::$persistentBuffer[get_class($this).$this->binary.$this->movieFile] = $output;
}
return $output;
}
}