为 HLS 创建主播放列表
Creating master playlist for HLS
我正在尝试使用 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
我在 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);
我正在尝试使用 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
我在 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);