【问题标题】:Creating master playlist for HLS为 HLS 创建主播放列表
【发布时间】:2018-02-28 13:18:06
【问题描述】:

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

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

【问题讨论】:

  • 到目前为止你尝试过什么?您收到什么错误消息?
  • 使用ffprobe 获取文件信息,如果这是问题。对于比特率,您应该已经知道目标值,因此只需在完成编码时添加ffmpeg 报告的复用开销。
  • @BPS 我已经尝试自己手动创建它,因为我在堆栈溢出时阅读了一个问题的答案,但现在我想自动化该过程
  • @aergistal 谢谢你的回复,你能指点我这样做的任何例子吗?
  • @Awaisfiaz ffprobe wiki

标签: php ffmpeg video-streaming video.js http-live-streaming


【解决方案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);

【讨论】:

  • 用PHP生成master,在智能手机上能用吗?我做过类似的事情,但无法在智能手机上重现直播:/
猜你喜欢
  • 2022-01-24
  • 1970-01-01
  • 1970-01-01
  • 2014-06-23
  • 2021-03-22
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多