|
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
|
|
|
|
|
22
|
|
|
class ExportHLSPlaylist |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param $filename |
|
26
|
|
|
* @param $representations |
|
27
|
|
|
* @param $basename |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function savePlayList($filename, $representations, $basename) |
|
30
|
|
|
{ |
|
31
|
|
|
file_put_contents($filename, static::generateContents($representations, $basename)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param $representations |
|
36
|
|
|
* @param $basename |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
private static function generateContents($representations, $basename) |
|
40
|
|
|
{ |
|
41
|
|
|
$content[] = "#EXTM3U"; |
|
|
|
|
|
|
42
|
|
|
$content[] = "#EXT-X-VERSION:3"; |
|
43
|
|
|
|
|
44
|
|
|
foreach ($representations as $representation) { |
|
45
|
|
|
if ($representation instanceof Representation) { |
|
46
|
|
|
$content[] = "#EXT-X-STREAM-INF:BANDWIDTH=" . $representation->getKiloBitrate() * 1024 . ",RESOLUTION=" . $representation->getResize(); |
|
47
|
|
|
$content[] = $basename . "_" . $representation->getHeight() . "p.m3u8"; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return implode(PHP_EOL, $content); |
|
52
|
|
|
} |
|
53
|
|
|
} |