This commit is contained in:
Brooke Vibber 2023-03-08 12:35:04 -08:00
parent cab52f32f9
commit 879832dbc9
3 changed files with 39 additions and 6 deletions

View file

@ -738,6 +738,7 @@ function playlist( $filename, $segments ) {
*/ */
$lines = []; $lines = [];
$lines[] = "#EXTM3U"; $lines[] = "#EXTM3U";
$lines[] = "#EXT-X-VERSION:7";
$lines[] = "#EXT-X-TARGETDURATION:10"; $lines[] = "#EXT-X-TARGETDURATION:10";
$lines[] = "#EXT-MEDIA-SEQUENCE:0"; $lines[] = "#EXT-MEDIA-SEQUENCE:0";
$lines[] = "#EXT-PLAYLIST-TYPE:VOD"; $lines[] = "#EXT-PLAYLIST-TYPE:VOD";
@ -750,10 +751,11 @@ function playlist( $filename, $segments ) {
$n = count( $segments ) - 1; $n = count( $segments ) - 1;
for ( $i = 0; $i < $n; $i++ ) { for ( $i = 0; $i < $n; $i++ ) {
$segment = $segments[$i]; $segment = $segments[$i];
$lines[] = "#EXTINF:{$segment['duration']}"; $lines[] = "#EXTINF:{$segment['duration']},";
$lines[] = "#EXT-X-BYTERANGE:{$segment['size']}@{$segment['start']}"; $lines[] = "#EXT-X-BYTERANGE:{$segment['size']}@{$segment['start']}";
$lines[] = $filename; $lines[] = $filename;
} }
$lines[] = "#EXT-X-ENDLIST";
return implode( "\n", $lines ); return implode( "\n", $lines );
} }

View file

@ -27,5 +27,32 @@
<source type=application/vnd.apple.mpegurl src=fmp4.vp9-h264.m3u8> <source type=application/vnd.apple.mpegurl src=fmp4.vp9-h264.m3u8>
</video> </video>
<h2>Component tracks</h2>
<p>HLS VP9 in fMP4:</p>
<video controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=fmp4.480p.vp9.mp4.m3u8>
</video>
<p>HLS h.264 in fMP4:</p>
<video controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=fmp4.480p.h264.mp4.m3u8>
</video>
<p>HLS Opus in fMP4:</p>
<video controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=fmp4.audio.opus.mp4.m3u8>
</video>
<p>HLS AAC in fMP4:</p>
<video controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=fmp4.audio.aac.mp4.m3u8>
</video>
<p>HLS MP3:</p>
<video controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=fmp4.audio.mpeg.mp3.m3u8>
</video>
</body> </body>
</html> </html>

View file

@ -28,33 +28,37 @@ while ( count( $argv ) > 0 ) {
$name = 'English'; // @fixme use correct unknown marker $name = 'English'; // @fixme use correct unknown marker
$language = 'en-US'; // @fixme $language = 'en-US'; // @fixme
$channels = 2; // @fixme $channels = 2; // @fixme
$uri = urlencode( $filename ); $uri = urlencode( $playlist );
$audio[$codec] = "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"$codec\",NAME=\"$name\",LANGUAGE=\"$language\",AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"$channels\",URI=\"$uri\""; $audio[$codec] = "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"$codec\",NAME=\"$name\",LANGUAGE=\"$language\",AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"$channels\",URI=\"$uri\"";
} else { } else {
$bandwidth = 1250000; // @fixme $bandwidth = 1250000; // @fixme
$width = 854; // @fixme $width = 854; // @fixme
$height = 480; // @fixme $height = 480; // @fixme
$fps = 24.0; // @fixme $fps = 24.0; // @fixme
$baseLine = "#EXT-X-STREAM-INFO:BANDWIDTH=$bandwidth,RESOLUTION={$width}x{$height},FRAME-RATE={$fps}"; $baseLine = "#EXT-X-STREAM-INF:BANDWIDTH=$bandwidth,RESOLUTION={$width}x{$height},FRAME-RATE={$fps}";
if ( count( $audio ) > 1 ) { if ( count( $audio ) > 1 ) {
foreach ( array_keys( $audio ) as $audioCodec ) { foreach ( array_keys( $audio ) as $audioCodec ) {
$codecs = implode( ',', [ $codecs = implode( ',', [
$videoCodecs[$codec], $videoCodecs[$codec],
$audioCodecs[$audioCodec], $audioCodecs[$audioCodec],
] ); ] );
$video[] = "$baseLine,CODECS=\"$codecs\""; $video[] = "$baseLine,CODECS=\"$codecs\",AUDIO=\"$audioCodec\"";
$video[] = $playlist; $video[] = $playlist;
} }
} else { } else {
$codecs = $videoCodecs[$codec]; $codecs = $videoCodecs[$codec];
$video[] = "$baseLine,CODECS=\"$codecs\",AUDIO=\"$audioCodec\""; $video[] = "$baseLine,CODECS=\"$codecs\"";
$video[] = $playlist; $video[] = $playlist;
} }
} }
} }
$header = [
'#EXTM3U',
];
$lines = array_merge( $lines = array_merge(
[ '#EXTM3U' ], $header,
array_values( $audio ), array_values( $audio ),
$video $video
); );