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\Filters; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
use Streaming\StreamInterface; |
17
|
|
|
use Streaming\Representation; |
18
|
|
|
use Streaming\Utiles; |
19
|
|
|
|
20
|
|
|
class DASHFilter extends FormatFilter |
21
|
|
|
{ |
22
|
|
|
/** @var \Streaming\DASH */ |
23
|
|
|
private $dash; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Representation $rep |
27
|
|
|
* @param int $key |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
private function getAudioBitrate(Representation $rep, int $key): array |
31
|
|
|
{ |
32
|
|
|
return $rep->getAudioKiloBitrate() ? ["-b:a:" . $key, $rep->getAudioKiloBitrate() . "k"] : []; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
private function streams(): array |
39
|
|
|
{ |
40
|
|
|
$streams = []; |
41
|
|
|
foreach ($this->dash->getRepresentations() as $key => $rep) { |
42
|
|
|
$streams = array_merge( |
43
|
|
|
$streams, |
44
|
|
|
Utiles::arrayToFFmpegOpt([ |
45
|
|
|
'map' => 0, |
46
|
|
|
"s:v:$key" => $rep->size2string(), |
47
|
|
|
"b:v:$key" => $rep->getKiloBitrate() . "k" |
48
|
|
|
]), |
49
|
|
|
$this->getAudioBitrate($rep, $key) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $streams; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
private function getAdaptions(): array |
60
|
|
|
{ |
61
|
|
|
return $this->dash->getAdaption() ? ['-adaptation_sets', $this->dash->getAdaption()] : []; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
private function init(): array |
68
|
|
|
{ |
69
|
|
|
$name = $this->dash->pathInfo(PATHINFO_FILENAME); |
70
|
|
|
|
71
|
|
|
$init = [ |
72
|
|
|
"use_timeline" => 1, |
73
|
|
|
"use_template" => 1, |
74
|
|
|
"init_seg_name" => $name . '_init_$RepresentationID$.$ext$', |
75
|
|
|
"media_seg_name" => $name . '_chunk_$RepresentationID$_$Number%05d$.$ext$', |
76
|
|
|
"seg_duration" => $this->dash->getSegDuration(), |
77
|
|
|
"hls_playlist" => (int)$this->dash->isGenerateHlsPlaylist(), |
78
|
|
|
"f" => "dash", |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
return array_merge( |
82
|
|
|
Utiles::arrayToFFmpegOpt($init), |
83
|
|
|
$this->getAdaptions(), |
84
|
|
|
Utiles::arrayToFFmpegOpt($this->dash->getAdditionalParams()) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
private function getArgs(): array |
92
|
|
|
{ |
93
|
|
|
return array_merge( |
94
|
|
|
$this->init(), |
95
|
|
|
$this->streams(), |
96
|
|
|
['-strict', $this->dash->getStrict()] |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param StreamInterface $dash |
102
|
|
|
*/ |
103
|
|
|
public function streamFilter(StreamInterface $dash): void |
104
|
|
|
{ |
105
|
|
|
$this->dash = $dash; |
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->filter = array_merge( |
108
|
|
|
$this->getFormatOptions($dash->getFormat()), |
109
|
|
|
$this->getArgs() |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.