91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
$argv = $_SERVER['argv'];
|
|
$self = array_shift( $argv );
|
|
$base = array_shift( $argv ); // "fmp4"
|
|
$audio = [];
|
|
$video = [];
|
|
|
|
$audioCodecs = [
|
|
'mpeg' => 'mp4a.40.34',
|
|
'aac' => 'mp4a.40.2',
|
|
'opus' => 'opus',
|
|
];
|
|
|
|
// @fixme use correct settings based on the file
|
|
$videoCodecs = [
|
|
'vp9' => 'vp09.00.10.08',
|
|
'h264' => 'avc1.42e00a',
|
|
|
|
//'mpeg4' => 'mp4v.20.9', // fail?
|
|
//'mpeg4' => 'mp4v.20',
|
|
|
|
// Lies for desktop safari
|
|
// 'mpeg4' => 'avc1', // lies
|
|
// 'h263' => 'avc1', // lies
|
|
|
|
'mjpeg' => 'jpeg', // works on mov, not mp4
|
|
|
|
// These lies work on iOS too
|
|
'h263' => 'avc1.42e00a', // lies
|
|
'mpeg4' => 'avc1.42e00a', // lies
|
|
//'mpeg4' => 'mp4v', // ???
|
|
//'h263' => 'h263', // ???
|
|
|
|
/*
|
|
'h264' => 'mp4v',
|
|
'h263' => 'mp4v',
|
|
'mjpeg' => 'mp4v',
|
|
'mpeg4' => 'mp4v',
|
|
*/
|
|
|
|
];
|
|
|
|
|
|
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
|
|
$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\"";
|
|
} else {
|
|
$bandwidth = 1250000; // @fixme
|
|
$width = 854; // @fixme
|
|
$height = 480; // @fixme
|
|
$fps = 24.0; // @fixme
|
|
$baseLine = "#EXT-X-STREAM-INF:BANDWIDTH=$bandwidth,RESOLUTION={$width}x{$height},FRAME-RATE={$fps}";
|
|
if ( count( $audio ) >= 1 ) {
|
|
foreach ( array_keys( $audio ) as $audioCodec ) {
|
|
$codecs = implode( ',', [
|
|
$videoCodecs[$codec],
|
|
$audioCodecs[$audioCodec],
|
|
] );
|
|
$video[] = "$baseLine,CODECS=\"$codecs\",AUDIO=\"$audioCodec\"";
|
|
$video[] = $playlist;
|
|
}
|
|
} else {
|
|
$codecs = $videoCodecs[$codec];
|
|
$video[] = "$baseLine,CODECS=\"$codecs\"";
|
|
$video[] = $playlist;
|
|
}
|
|
}
|
|
}
|
|
|
|
$header = [
|
|
'#EXTM3U',
|
|
];
|
|
|
|
$lines = array_merge(
|
|
$header,
|
|
array_values( $audio ),
|
|
$video
|
|
);
|
|
|
|
$m3u8 = implode( "\n", $lines );
|
|
print "$m3u8\n";
|