1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the PHP-FFmpeg-video-streaming package. |
5
|
|
|
* |
6
|
|
|
* (c) Amin Yazdanpanah <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
namespace Streaming\MediaInfo\Streams; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class Stream implements \Countable |
17
|
|
|
{ |
18
|
|
|
private $stream; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param array $stream |
22
|
|
|
*/ |
23
|
|
|
public function __construct(array $stream) |
24
|
|
|
{ |
25
|
|
|
$this->stream = $stream; |
26
|
|
|
|
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array $attr |
32
|
|
|
* @param bool $string |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function get($attr = ['*'], $string = true) |
36
|
|
|
{ |
37
|
|
|
if (!is_array($attr)) { |
|
|
|
|
38
|
|
|
$attr = array($attr); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$out = array_filter($this->stream, function ($key) use ($attr) { |
42
|
|
|
return in_array($key, $attr) || current($attr) === "*"; |
43
|
|
|
}, ARRAY_FILTER_USE_KEY); |
44
|
|
|
|
45
|
|
|
return ($string) ? implode(',', $out) : $out; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $attr |
50
|
|
|
* @param bool $string |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function except($attr, $string = false) |
54
|
|
|
{ |
55
|
|
|
if (!is_array($attr)) { |
56
|
|
|
$attr = array($attr); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$out = array_filter($this->stream, function ($key) use ($attr) { |
60
|
|
|
return !in_array($key, $attr); |
61
|
|
|
}, ARRAY_FILTER_USE_KEY); |
62
|
|
|
|
63
|
|
|
return ($string) ? implode(',', $out) : $out; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function isAudio() |
70
|
|
|
{ |
71
|
|
|
return $this->get('@type', true) === 'Audio'; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function isVideo() |
78
|
|
|
{ |
79
|
|
|
return $this->get('@type', true) === 'Video'; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
public function keys() |
86
|
|
|
{ |
87
|
|
|
return array_keys($this->stream); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function all() |
94
|
|
|
{ |
95
|
|
|
return $this->stream; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param $attr |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
public function has($attr) |
103
|
|
|
{ |
104
|
|
|
return isset($this->stream[$attr]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return int |
109
|
|
|
*/ |
110
|
|
|
public function count() |
111
|
|
|
{ |
112
|
|
|
return count($this->stream); |
113
|
|
|
} |
114
|
|
|
} |