WIP on HLS

got the HLS working on all browsers with VP9+AAC
now to try getting the MP3 and Opus working
This commit is contained in:
Brooke Vibber 2021-10-22 15:37:37 -07:00
parent 68691c29ad
commit 5a4e9aa6bb
5 changed files with 174 additions and 55 deletions

View file

@ -0,0 +1,29 @@
#EXTM3U
# Define the audio tracks for Opus and MP3
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="opus",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="caminandes-llamigos.webm.audio.opus.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="mp3",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="caminandes-llamigos.webm.audio.mp3.m3u8"
# Opus-based preferred
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.1080p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.720p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=875000,RESOLUTION=854x480,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.480p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.360p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=275000,RESOLUTION=426x240,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.240p.vp9.pass2.mp4.m3u8
# MP3 for Safari
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.1080p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.720p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=875000,RESOLUTION=854x480,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.480p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.360p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=275000,RESOLUTION=426x240,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.240p.vp9.pass2.mp4.m3u8

View file

@ -0,0 +1,42 @@
#EXTM3U
# Define the audio tracks for Opus and MP3
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="opus",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="caminandes-llamigos.webm.audio.opus.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="caminandes-llamigos.webm.audio.aac.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="mp3",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="caminandes-llamigos.webm.audio.mp3.m3u8"
# Opus-based preferred
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,FRAME-RATE=24.0,CODECS="vp09.00.10.08,Opus",AUDIO="opus"
caminandes-llamigos.webm.1080p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=24.0,CODECS="vp09.00.10.08,Opus",AUDIO="opus"
caminandes-llamigos.webm.720p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=875000,RESOLUTION=854x480,FRAME-RATE=24.0,CODECS="vp09.00.10.08,Opus",AUDIO="opus"
caminandes-llamigos.webm.480p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360,FRAME-RATE=24.0,CODECS="vp09.00.10.08,Opus",AUDIO="opus"
caminandes-llamigos.webm.360p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=275000,RESOLUTION=426x240,FRAME-RATE=24.0,CODECS="vp09.00.10.08,Opus",AUDIO="opus"
caminandes-llamigos.webm.240p.vp9.pass2.mp4.m3u8
# AAC-based temporary experiment (may not be able to use)
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.02",AUDIO="aac"
caminandes-llamigos.webm.1080p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.02",AUDIO="aac"
caminandes-llamigos.webm.720p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=875000,RESOLUTION=854x480,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.02",AUDIO="aac"
caminandes-llamigos.webm.480p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.02",AUDIO="aac"
caminandes-llamigos.webm.360p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=275000,RESOLUTION=426x240,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.02",AUDIO="aac"
caminandes-llamigos.webm.240p.vp9.pass2.mp4.m3u8
# MP3 for Safari
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.1080p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.720p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=875000,RESOLUTION=854x480,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.480p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.360p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=275000,RESOLUTION=426x240,FRAME-RATE=24.0,CODECS="vp09.00.10.08,mp4a.40.34",AUDIO="mp3"
caminandes-llamigos.webm.240p.vp9.pass2.mp4.m3u8

16
llamigos-vp9-opus.m3u8 Normal file
View file

@ -0,0 +1,16 @@
#EXTM3U
# Define the audio tracks for Opus
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="opus",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="caminandes-llamigos.webm.audio.opus.m3u8"
# Opus-based preferred
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.1080p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.720p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=875000,RESOLUTION=854x480,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.480p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=375000,RESOLUTION=640x360,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.360p.vp9.pass2.mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=275000,RESOLUTION=426x240,FRAME-RATE=24.0,CODECS="vp09.00.10.08,opus",AUDIO="opus"
caminandes-llamigos.webm.240p.vp9.pass2.mp4.m3u8

135
ogv.html
View file

@ -9,43 +9,61 @@
<h1>HLS WebM test</h1>
<p id=hls>Checking HLS support...</p>
<p id=mse>Checking MSE support...</p>
<p id=mse>Checking MSE VP9 support...</p>
<p id=webm>Checking flat WebM VP8 / Vorbis support...</p>
<p id=webm2>Checking flat WebM generic support...</p>
<p id=wasm>Checking WebAssembly support...</p>
<h2>Caminandes - Llamigos</h2>
<!--
<p>HLS with Opus-in-MP4 and elementary MP3 audio (mp4a.40.34) and VP9-in-MP4 at several resolutions, with a flat WebM VP8/Vorbis fallback:</p>
<video id=hls1 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-mp3-opus.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>HLS with AAC audio and VP9-in-MP4 at several resolutions:</p>
<video id=hls0 controls width=640 height=360>
<p>Expected behavior:</p>
<ul>
<li>Firefox/Chrome: play via MSE with VP9/Opus</li>
<li>Desktop Safari with VP9 support: play via MSE with VP9/MP3</li>
<li>iOS Safari with VP9 support: play native HLS with VP9/MP3</li>
<li>Older iOS and desktop Safari without VP9: play via ogv.js with WebM VP8/Vorbis</li>
<li>Very old Firefox/Chrome: play native WebM VP8/Vorbis</li>
<li>edge cases: :(</li>
</ul>
-->
<!--
<p>HLS with VP9 video and Opus, AAC, and MP3 audio. Flag WebM fallback.</p>
<video id=hls1 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-opus-aac-mp3.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>Expected behavior:</p>
<ul>
<li>Firefox/Chrome: MSE VP9/Opus (AAC for now)</li>
<li>Desktop Safari with VP9 support: MSE VP9/MP3 (AAC for now?)</li>
<li>iOS Safari with VP9 support: HLS VP9/MP3 (AAC for now?)</li>
<li>Older iOS and desktop Safari without VP9: ogv.js VP8/Vorbis</li>
<li>Very old Firefox/Chrome: native WebM VP8/Vorbis</li>
</ul>
-->
<p>HLS with VP9 video and Opus, AAC, and MP3 audio. Flag WebM fallback.</p>
<video id=hls1 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-aac.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>HLS with MP3 audio (mp4a.40.34) and VP9-in-MP4 at several resolutions:</p>
<video id=hls1 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-mp3.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>HLS with MP3 audio (mp4a.6b) and VP9-in-MP4 at several resolutions:</p>
<video id=hls2 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-mp3b.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>HLS with MP3 audio (mp3) and VP9-in-MP4 at several resolutions:</p>
<video id=hls3 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-mp3c.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>HLS with elementary MP3 audio (mp4a.40.34) and VP9-in-MP4 at several resolutions:</p>
<video id=hls4 controls width=640 height=360>
<source type=application/vnd.apple.mpegurl src=llamigos-vp9-mp3d.m3u8>
<source type=video/webm src=caminandes-llamigos.webm.flat.webm>
</video>
<p>Expected behavior:</p>
<ul>
<li>Firefox/Chrome: MSE VP9/Opus (AAC for now)</li>
<li>Desktop Safari with VP9 support: MSE VP9/MP3 (AAC for now?)</li>
<li>iOS Safari with VP9 support: HLS VP9/MP3 (AAC for now?)</li>
<li>Older iOS and desktop Safari without VP9: ogv.js VP8/Vorbis</li>
<li>Very old Firefox/Chrome: native WebM VP8/Vorbis</li>
</ul>
<script>
if (hls1.canPlayType('application/vnd.apple.mpegurl')) {
@ -56,32 +74,38 @@
hls.style.color = 'red';
}
if (typeof MediaSource == 'function') {
if (MediaSource.isTypeSupported('video/mp4; codecs="vp09.00.10.08"') &&
MediaSource.isTypeSupported('audio/mp4; codecs="mp4a.40.02"')) {
mse.textContent = 'MSE supports VP9 & AAC-LC in MP4';
let codecs = [
['VP9-in-MP4', 'video/mp4; codecs="vp09.00.10.08"'],
['Opus-in-MP4', 'audio/mp4; codecs="opus"'],
['MP3', 'audio/mp3'],
];
let yes = [];
let no = [];
for (let [name, mime] of codecs) {
if (MediaSource.isTypeSupported(mime)) {
yes.push(name);
} else {
no.push(name);
}
}
if (yes.length == codecs.length) {
mse.textContent = 'MSE supports ' + yes.join(', ');
mse.style.color = 'green';
} else {
mse.textContent = 'MSE doesn\'t support one of VP9 or AAC in MP4';
mse.textContent = 'MSE supports ' + yes.join(', ') + ' but not ' + no.join(', ');
mse.style.color = 'orange';
}
} else {
mse.textContent = 'MSE not supported';
mse.style.color = 'red';
}
if (hls1.canPlayType('video/webm')) {
webm.textContent = 'flat WebM generic supported';
if (hls1.canPlayType('video/webm; codecs="vp8, vorbis"')) {
webm.textContent = 'flat WebM VP8/Vorbis supported';
webm.style.color = 'green';
} else {
webm.textContent = 'flat WebM generic not supported';
webm.textContent = 'flat WebM VP8/Vorbis not supported';
webm.style.color = 'red';
}
if (hls1.canPlayType('video/webm; codecs="vp8, vorbis"')) {
webm2.textContent = 'flat WebM VP8/Vorbis supported';
webm2.style.color = 'green';
} else {
webm2.textContent = 'flat WebM VP8/Vorbis not supported';
webm2.style.color = 'red';
}
if (typeof WebAssembly == 'object') {
wasm.textContent = 'WebAssembly supported';
wasm.style.color = 'green';
@ -90,13 +114,10 @@
wasm.style.color = 'red';
}
</script>
<!--
<script src=ogvjs-1.8.4/ogv.js></script>
<script src=video-js/video.js></script>
<script src=videojs-ogvjs.js></script>
<script type=text/x-disabled>
<script>
var playerConfig = {
responsive: true,
controlBar: {
@ -109,15 +130,25 @@
html5: {}
};
var mse = (typeof MediaSource == 'function') &&
MediaSource.isTypeSupported('video/mp4; codecs="vp09.00.10.08"') &&
MediaSource.isTypeSupported('audio/mp4; codecs="mp4a.40.02"');
function can(mime) {
return (typeof MediaSource == 'function') && MediaSource.isTypeSupported(mime);
}
var vp9 = can('video/mp4; codecs="vp09.00.10.08"');
var opus = can('audio/mp4; codecs="opus"');
var aac = can('audio/mp4; codecs="mp4a.40.02')
var mp3 = can('audio/mp3');
//var mse = vp9 && (opus || mp3);
//var mse = vp9 && mp3;
var mse = vp9 && aac;
if (mse) {
// enable streaming plugin
playerConfig.html5.vhs = {
overrideNative: true,
useDevicePixelRatio: true
};
console.log('will do mse');
} else {
console.log('wont do mse');
}
var webm = null;
@ -135,7 +166,7 @@
(typeof WebAssembly.Module == 'function');
if (ogv) {
console.log('can do ogvjs');
var base = new URL('./ogvjs-1.8.4', document.location)
var base = new URL('./ogvjs-1.8.4', document.location.pathname)
console.log(base);
console.log(base.pathname);
playerConfig.ogvjs = {
@ -146,6 +177,8 @@
} else {
console.log('wont do ogvjs');
}
videojs.log.level('debug');
hls1.classList.add('video-js');
hls1.classList.add('vjs-default-skin');
@ -169,8 +202,8 @@
vjs1.off('error', failover);
});
vjs1.load();
// this fails on Chrome with a blob issue on the HLS player :D
//vjs1.load();
</script>
-->
</body>
</html>

View file

@ -209,7 +209,8 @@ class Transcoder {
$segmentOptions = [];
if ( $container == 'mp4' ) {
$segmentOptions[] = '-segment_format_options';
$segmentOptions[] = 'movflags=+frag_keyframe+empty_moov';
//$segmentOptions[] = 'movflags=+frag_keyframe+empty_moov';
$segmentOptions[] = 'movflags=frag_keyframe';
}
if ( $container == 'mp3' ) {
$segmentOptions[] = '-segment_format_options';
@ -293,9 +294,8 @@ $infiles = [
foreach ( $infiles as $filename ) {
$source = new SourceFile( $filename );
$codec = new Transcoder( $source );
//$codec->audio('opus');
$codec->audio('opus');
$codec->audio('mp3');
/*
$codec->audio('aac');
foreach ( Video::FORMATS['vp9']['resolutions'] as $res => $format ) {
@ -305,5 +305,4 @@ foreach ( $infiles as $filename ) {
$codec->video('vp9', $res, 'pass2');
}
}
*/
}