简体   繁体   English

为 HLS 创建主播放列表

[英]Creating master playlist for HLS

I am trying to implement adaptive stream using HLS I have video encoded in 4 different resolution with .m3u8 extension我正在尝试使用HLS实现自适应流我有 4 种不同分辨率的视频编码,扩展名为.m3u8

legend_240.m3u8
legend_360.m3u8
legend_480.m3u8
legend_720.m3u8

I encoded them using FFMPEG now I want to wrap them all in a master HLS playlist.我现在使用FFMPEG它们进行编码,我想将它们全部包装在主HLS播放列表中。 How can I achieve this in an automated process?如何在自动化过程中实现这一目标?

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=17556000,RESOLUTION=428x240
legend_240.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=28556000,RESOLUTION=640x360
legend_360.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=56056000,RESOLUTION=854x480
legend_480.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=73056000,RESOLUTION=1280x720
legend_720.m3u8

I figured it out using file handling in php.我在 php 中使用文件处理解决了这个问题。

        $myfile = fopen($this->raw_path."/".$this->file_name.".m3u8", "w") or die("Unable to open file!");

        $txt = "#EXTM3U\n";

        fwrite($myfile, $txt);

        $txt = "#EXT-X-VERSION:3\n";

        fwrite($myfile, $txt);
        // fclose($myfile);
        if($convertedRes['720']){

        $txt = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=73056000,RESOLUTION=1280x720\n";
        fwrite($myfile, $txt);
        $txt = $this->file_name."/".$this->file_name."-720.m3u8\n";
        fwrite($myfile, $txt);

        }
        if($convertedRes['480']){

        $txt = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=5605600,RESOLUTION=854x480\n";
        fwrite($myfile, $txt);
        $txt = $this->file_name."/".$this->file_name."-480.m3u8\n";
        fwrite($myfile, $txt);

        }

        if($convertedRes['360']){

        $txt = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2855600,RESOLUTION=640x360\n";
        fwrite($myfile, $txt);
        $txt = $this->file_name."/".$this->file_name."-360.m3u8\n";
        fwrite($myfile, $txt);

        }

        if($convertedRes['240']){


        $txt = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1755600,RESOLUTION=428x240\n";
        fwrite($myfile, $txt);
        $txt = $this->file_name."/".$this->file_name."-240.m3u8\n";
        fwrite($myfile, $txt);


        }


fclose($myfile);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM