/
FfmpegParser.php
90 lines (82 loc) · 2.82 KB
/
FfmpegParser.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* This file is part of the PHP Video Toolkit v2 package.
*
* @author Oliver Lillie (aka buggedcom) <publicmail@buggedcom.co.uk>
* @license Dual licensed under MIT and GPLv2
* @copyright Copyright (c) 2008-2014 Oliver Lillie <http://www.buggedcom.co.uk>
* @package PHPVideoToolkit V2
* @version 2.1.7-beta
* @uses ffmpeg http://ffmpeg.sourceforge.net/
*/
namespace PHPVideoToolkit;
/**
* This is a container class for determining which ffmpeg parser class to use to be able to correctly parser the data
* returned by the ffmpeg that is installed on the system.
*
* @author Oliver Lillie
*/
class FfmpegParser
{
protected $_parser;
protected $_config;
/**
* Constructor
*
* @access public
* @author: Oliver Lillie
* @param Config $config The config object.
*/
public function __construct(Config $config=null)
{
$this->_config = $config === null ? Config::getInstance() : $config;
$this->_parser = null;
}
/**
* Gets the specific ffmpeg parser to use based upon the format data.
*
* @access public
* @author Oliver Lillie
* @return mixed Returns either PHPVideoToolkit\FfmpegParserFormatsArgumentOnly or PHPVideoToolkit\FfmpegParserGeneric
* depending on what information is return in the format data.
*/
protected function _getParser()
{
$parser = new Parser($this->_config);
$format_data = $parser->getRawFormatData();
if(strpos($format_data, 'Codecs:') !== false)
{
$this->_parser = new FfmpegParserFormatsArgumentOnly($this->_config);
}
else
{
$this->_parser = new FfmpegParserGeneric($this->_config);
}
return $this->_parser;
}
/**
* Calls any method in the contained $_parser class.
*
* @access public
* @author Oliver Lillie
* @param string $name
* @param string $arguments
* @return mixed
* @throws \BadMethodCallException if the function does not exist in the parser.
*/
public function __call($name, $arguments)
{
if($this->_parser === null)
{
$this->_getParser();
}
if(method_exists($this->_parser, $name) === true)
{
return call_user_func_array(array($this->_parser, $name), $arguments);
}
else
{
throw new \BadMethodCallException('`'.$name.'` is not a valid parser function.');
}
}
}