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
|
|
|
namespace Streaming\Filters; |
13
|
|
|
|
14
|
|
|
use Streaming\HLS; |
15
|
|
|
use Streaming\Representation; |
16
|
|
|
|
17
|
|
|
class HLSFilter extends Filter |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param $media |
21
|
|
|
* @return mixed|void |
22
|
|
|
*/ |
23
|
|
|
public function setFilter($media): void |
24
|
|
|
{ |
25
|
|
|
$this->filter = $this->HLSFilter($media); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param HLS $media |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
private function HLSFilter(HLS $media) |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
$filter = []; |
36
|
|
|
$total_count = count($representations = $media->getRepresentations()); |
37
|
|
|
$counter = 0; |
38
|
|
|
$path_parts = $media->getPathInfo(); |
39
|
|
|
$dirname = str_replace("\\", "/", $path_parts["dirname"]); |
40
|
|
|
$filename = substr($path_parts["filename"], -50); |
41
|
|
|
|
42
|
|
|
foreach ($representations as $representation) { |
43
|
|
|
if ($representation instanceof Representation) { |
44
|
|
|
$filter[] = "-s:v"; |
45
|
|
|
$filter[] = $representation->getResize(); |
46
|
|
|
$filter[] = "-crf"; |
47
|
|
|
$filter[] = "20"; |
48
|
|
|
$filter[] = "-sc_threshold"; |
49
|
|
|
$filter[] = "0"; |
50
|
|
|
$filter[] = "-g"; |
51
|
|
|
$filter[] = "48"; |
52
|
|
|
$filter[] = "-keyint_min"; |
53
|
|
|
$filter[] = "48"; |
54
|
|
|
$filter[] = "-hls_list_size"; |
55
|
|
|
$filter[] = "0"; |
56
|
|
|
$filter[] = "-hls_time"; |
57
|
|
|
$filter[] = $media->getHlsTime(); |
58
|
|
|
$filter[] = "-hls_allow_cache"; |
59
|
|
|
$filter[] = $media->isHlsAllowCache() ? "1" : "0"; |
60
|
|
|
$filter[] = "-b:v"; |
61
|
|
|
$filter[] = $representation->getKiloBitrate() . "k"; |
62
|
|
|
$filter[] = "-maxrate"; |
63
|
|
|
$filter[] = intval($representation->getKiloBitrate() * 1.2) . "k"; |
64
|
|
|
$filter[] = "-hls_segment_filename"; |
65
|
|
|
$filter[] = $dirname . "/" . $filename . "_" . $representation->getHeight() . "p_%04d.ts"; |
66
|
|
|
|
67
|
|
|
if (($hls_key_info_file = $media->getHlsKeyInfoFile()) !== "") { |
68
|
|
|
$filter[] = "-hls_key_info_file"; |
69
|
|
|
$filter[] = $hls_key_info_file; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (++$counter !== $total_count) { |
73
|
|
|
$filter[] = $dirname . "/" . $filename . "_" . $representation->getHeight() . "p.m3u8"; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $filter; |
79
|
|
|
} |
80
|
|
|
} |