为HLS创建主播放列表

时间:2017-09-19 16:45:49

标签: php ffmpeg video-streaming video.js hls

我正在尝试使用HLS实现自适应流我使用.m3u8扩展名以4种不同的分辨率编码视频

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

我使用FFMPEG编码它们现在我想将它们全部包装在主HLS播放列表中。如何在自动化过程中实现这一目标?

#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

1 个答案:

答案 0 :(得分:1)

我在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);