gpt4 book ai didi

php - 为 HLS 创建主播放列表

转载 作者:行者123 更新时间:2023-12-04 22:55:43 26 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

我在 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 - 为 HLS 创建主播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46305780/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com