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
|
|
|
|
20
|
|
|
namespace AYazdanpanah\FFMpegStreaming\Filters; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
use AYazdanpanah\FFMpegStreaming\DASH; |
24
|
|
|
use AYazdanpanah\FFMpegStreaming\Format\X264; |
25
|
|
|
use AYazdanpanah\FFMpegStreaming\Representation; |
26
|
|
|
|
27
|
|
|
class DASHFilter extends Filter |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @param $media |
31
|
|
|
*/ |
32
|
|
|
public function setFilter($media): void |
33
|
|
|
{ |
34
|
|
|
$this->filter = $this->DASHFilter($media); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param DASH $media |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
private function DASHFilter(DASH $media) |
42
|
|
|
{ |
43
|
|
|
$filter = $this->getAdditionalFilters($media->getFormat(), count($media->getRepresentations())); |
44
|
|
|
|
45
|
|
|
foreach ($media->getRepresentations() as $key => $representation) { |
46
|
|
|
if ($representation instanceof Representation) { |
47
|
|
|
$filter[] = "-map"; |
48
|
|
|
$filter[] = "0"; |
49
|
|
|
$filter[] = "-b:v:" . $key; |
50
|
|
|
$filter[] = $representation->getKiloBitrate() . "k"; |
51
|
|
|
|
52
|
|
|
if (null !== $representation->getResize()) { |
53
|
|
|
$filter[] = "-s:v:" . $key; |
54
|
|
|
$filter[] = $representation->getResize(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($media->getAdaption()) { |
60
|
|
|
$filter[] = "-adaptation_sets"; |
61
|
|
|
$filter[] = $media->getAdaption(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $filter; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function getAdditionalFilters($format, $count) |
68
|
|
|
{ |
69
|
|
|
$filter = [ |
70
|
|
|
"-bf", "1", "-keyint_min", "120", "-g", "120", |
71
|
|
|
"-sc_threshold", "0", "-b_strategy", "0", |
72
|
|
|
"-use_timeline", "1", "-use_template", "1", "-f", "dash" |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
if ($format instanceof X264) { |
76
|
|
|
$filter[] = "-profile:v:0"; |
77
|
|
|
$filter[] = "main"; |
78
|
|
|
|
79
|
|
|
while ($count > 0) { |
80
|
|
|
$filter[] = "-profile:v:" . $count; |
81
|
|
|
$filter[] = "baseline"; |
82
|
|
|
$count--; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $filter; |
87
|
|
|
} |
88
|
|
|
} |