hls-test/meta-playlist.php

99 lines
2.7 KiB
PHP
Raw Permalink Normal View History

2023-03-08 19:21:37 +00:00
<?php
$argv = $_SERVER['argv'];
$self = array_shift( $argv );
2023-03-30 17:20:15 +00:00
if ( ( $argv[0] ?? '' ) === '--lie') {
2023-03-30 18:46:39 +00:00
array_shift( $argv );
$lie = 'avc1.42e00a';
} elseif ( preg_match( '/^--lie=(.*)$/', $argv[0] ?? '', $matches ) ) {
array_shift( $argv );
$lie = $matches[1];
2023-03-30 17:20:15 +00:00
} else {
$lie = false;
}
2023-03-08 19:21:37 +00:00
$base = array_shift( $argv ); // "fmp4"
$audio = [];
$video = [];
$audioCodecs = [
2023-03-30 17:20:15 +00:00
'mpeg' => 'mp4a.6b', // works but, technically this is for .fmp4 and we're in mp3 raw
2023-03-29 23:08:31 +00:00
//'mpeg' => 'mp3', // doesn't seem to work
'aac' => 'mp4a.40.2',
'opus' => 'opus',
2023-04-03 03:27:16 +00:00
'alac' => 'alac',
2023-04-15 00:18:22 +00:00
'flac' => 'flac',
'ulaw' => 'ulaw',
'alaw' => 'alaw',
2023-03-08 19:21:37 +00:00
];
// @fixme use correct settings based on the file
$videoCodecs = [
2023-03-30 17:20:15 +00:00
'vp9' => 'vp09.00.41.08',
2023-04-14 21:34:48 +00:00
'vp8' => 'vp08.0.0.08',
2023-03-08 19:21:37 +00:00
'h264' => 'avc1.42e00a',
2023-03-27 21:41:21 +00:00
2023-03-29 17:59:47 +00:00
// truths
2023-03-30 17:20:15 +00:00
'mjpeg' => 'jpeg', // works on current mac & iOS 16, but not iOS 10
'h263' => 's263', // fail? or should it be s263?
'mpeg4' => 'mp4v.20.9', // fail?
2023-03-27 21:41:21 +00:00
2023-03-29 23:08:31 +00:00
// none of them seem to work on iOS 12!
2023-03-30 17:20:15 +00:00
];
2023-03-29 23:08:31 +00:00
2023-03-30 17:20:15 +00:00
if ( $lie ) {
2023-03-29 23:08:31 +00:00
// These lies work on iOS 10 and iOS 16 too
2023-03-30 18:46:39 +00:00
$videoCodecs['mjpeg'] = $lie;
$videoCodecs['h263' ] = $lie;
$videoCodecs['mpeg4'] = $lie;
2023-04-14 21:34:48 +00:00
$videoCodecs['vp8'] = $lie;
2023-03-30 17:20:15 +00:00
}
2023-03-08 19:21:37 +00:00
while ( count( $argv ) > 0 ) {
$track = array_shift( $argv );
[ $res, $codec, $ext ] = explode( '.', $track, 3 );
$filename = "$base.$res.$codec.$ext";
$playlist = "$filename.m3u8";
if ( $res === 'audio' ) {
$name = 'English'; // @fixme use correct unknown marker
$language = 'en-US'; // @fixme
$channels = 2; // @fixme
2023-03-08 20:35:04 +00:00
$uri = urlencode( $playlist );
2023-03-08 19:21:37 +00:00
$audio[$codec] = "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"$codec\",NAME=\"$name\",LANGUAGE=\"$language\",AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"$channels\",URI=\"$uri\"";
} else {
$bandwidth = 1250000; // @fixme
$width = 854; // @fixme
$height = 480; // @fixme
$fps = 24.0; // @fixme
2023-03-08 20:35:04 +00:00
$baseLine = "#EXT-X-STREAM-INF:BANDWIDTH=$bandwidth,RESOLUTION={$width}x{$height},FRAME-RATE={$fps}";
if ( count( $audio ) >= 1 ) {
2023-03-08 19:21:37 +00:00
foreach ( array_keys( $audio ) as $audioCodec ) {
$codecs = implode( ',', [
$videoCodecs[$codec],
$audioCodecs[$audioCodec],
] );
2023-03-08 20:35:04 +00:00
$video[] = "$baseLine,CODECS=\"$codecs\",AUDIO=\"$audioCodec\"";
2023-03-08 20:03:23 +00:00
$video[] = $playlist;
2023-03-08 19:21:37 +00:00
}
} else {
$codecs = $videoCodecs[$codec];
2023-03-08 20:35:04 +00:00
$video[] = "$baseLine,CODECS=\"$codecs\"";
2023-03-08 20:03:23 +00:00
$video[] = $playlist;
2023-03-08 19:21:37 +00:00
}
}
}
2023-03-08 20:35:04 +00:00
$header = [
'#EXTM3U',
];
2023-03-08 20:03:23 +00:00
$lines = array_merge(
2023-03-08 20:35:04 +00:00
$header,
2023-03-08 19:21:37 +00:00
array_values( $audio ),
$video
);
$m3u8 = implode( "\n", $lines );
2023-03-08 20:03:23 +00:00
print "$m3u8\n";