1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the MIT License; |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* https://opensource.org/licenses/MIT |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace AYazdanpanah\FFMpegStreaming; |
20
|
|
|
|
21
|
|
|
use AYazdanpanah\FFMpegStreaming\Format\X264; |
22
|
|
|
use FFMpeg\Filters\FilterInterface; |
23
|
|
|
|
24
|
|
|
class Filter implements FilterInterface |
25
|
|
|
{ |
26
|
|
|
private $priority = 2; |
27
|
|
|
|
28
|
|
|
private $filter = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Filter constructor. |
32
|
|
|
* @param Export $media |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Export $media) |
35
|
|
|
{ |
36
|
|
|
$this->setFilter($media); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Applies the filter on the the Audio media given an format. |
42
|
|
|
* |
43
|
|
|
* @return array An array of arguments |
44
|
|
|
*/ |
45
|
|
|
public function apply(): array |
46
|
|
|
{ |
47
|
|
|
return $this->getFilter(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the priority of the filter. |
52
|
|
|
* |
53
|
|
|
* @return integer |
54
|
|
|
*/ |
55
|
|
|
public function getPriority(): int |
56
|
|
|
{ |
57
|
|
|
return $this->priority; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getFilter(): array |
64
|
|
|
{ |
65
|
|
|
return $this->filter; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $media |
70
|
|
|
*/ |
71
|
|
|
public function setFilter(Export $media): void |
72
|
|
|
{ |
73
|
|
|
if ($media instanceof DASH) { |
74
|
|
|
$this->filter = $this->DASHFilter($media); |
75
|
|
|
} elseif ($media instanceof HLS) { |
76
|
|
|
$this->filter = $this->HLSFilter($media); |
77
|
|
|
} elseif ($media instanceof Live) { |
78
|
|
|
$this->filter = $this->liveFilter($media); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param DASH $media |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
private function DASHFilter(DASH $media) |
87
|
|
|
{ |
88
|
|
|
$filter = $this->getDASHFilter(); |
89
|
|
|
|
90
|
|
|
if($media->format instanceof X264){ |
91
|
|
|
$filter[] = "-profile:v:0"; |
92
|
|
|
$filter[] = "main"; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
foreach ($media->getRepresentations() as $key => $representation) { |
96
|
|
|
if ($representation instanceof Representation) { |
97
|
|
|
$filter[] = "-map"; |
98
|
|
|
$filter[] = "0"; |
99
|
|
|
$filter[] = "-b:v:" . $key; |
100
|
|
|
$filter[] = $representation->getKiloBitrate() . "k"; |
101
|
|
|
if (null !== $representation->getResize()) { |
102
|
|
|
$filter[] = "-s:v:" . $key; |
103
|
|
|
$filter[] = $representation->getResize(); |
104
|
|
|
} |
105
|
|
|
if ($key > 0 && $media->format instanceof X264) { |
106
|
|
|
$filter[] = "-profile:v:" . $key; |
107
|
|
|
$filter[] = "baseline"; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if ($media->getAdaption()) { |
113
|
|
|
$filter[] = "-adaptation_sets"; |
114
|
|
|
$filter[] = $media->getAdaption(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $filter; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param HLS $media |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
|
|
private function HLSFilter(HLS $media) |
125
|
|
|
{ |
126
|
|
|
$filter = [ |
127
|
|
|
"-f", |
128
|
|
|
"hls" |
129
|
|
|
]; |
130
|
|
|
|
131
|
|
|
foreach ($media->getRepresentations() as $key => $representation) { |
132
|
|
|
if ($representation instanceof Representation) { |
133
|
|
|
$filter[] = "-map"; |
134
|
|
|
$filter[] = "0:v"; |
135
|
|
|
$filter[] = "-b:v:" . $key; |
136
|
|
|
$filter[] = $representation->getKiloBitrate() . "k"; |
137
|
|
|
if (null !== $representation->getResize()) { |
138
|
|
|
$filter[] = "-s:v:" . $key; |
139
|
|
|
$filter[] = $representation->getResize(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if ($media->getStreamMap()) { |
145
|
|
|
$filter[] = "-var_stream_map"; |
146
|
|
|
$filter[] = $media->getStreamMap(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return $filter; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param Live $media |
154
|
|
|
*/ |
155
|
|
|
private function liveFilter(Live $media) |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
die("Live (Soon)"); |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
private function getDASHFilter() |
161
|
|
|
{ |
162
|
|
|
return [ |
163
|
|
|
"-bf", |
164
|
|
|
"1", |
165
|
|
|
"-keyint_min", |
166
|
|
|
"120", |
167
|
|
|
"-g", |
168
|
|
|
"120", |
169
|
|
|
"-sc_threshold", |
170
|
|
|
"0", |
171
|
|
|
"-b_strategy", |
172
|
|
|
"0", |
173
|
|
|
"-use_timeline", |
174
|
|
|
"1", |
175
|
|
|
"-use_template", |
176
|
|
|
"1", |
177
|
|
|
"-f", |
178
|
|
|
"dash" |
179
|
|
|
]; |
180
|
|
|
} |
181
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.