Add CMAF format and CMAF/init segment support to HLS muxer

This commit is contained in:
Vanilagy
2026-03-30 17:06:57 +02:00
parent 7b70756961
commit 3bcbcc13f0
16 changed files with 766 additions and 178 deletions
@@ -13,6 +13,7 @@ import {
MpegTsOutputFormat,
AdtsOutputFormat,
StreamTarget,
CmafOutputFormat,
} from 'mediabunny';
const durationSlider = document.querySelector('#duration-slider') as HTMLInputElement;
@@ -119,8 +120,8 @@ const generateVideo = async () => {
*/
},
format: new HlsOutputFormat({
segmentFormats: [new AdtsOutputFormat(), new MpegTsOutputFormat()],
// singleFilePerPlaylist: true,
segmentFormat: new CmafOutputFormat(),
singleFilePerPlaylist: true,
getPlaylistPath: info => `sussex-${info.n}.m3u8`,
}),
});
@@ -146,7 +147,7 @@ const generateVideo = async () => {
// For audio, we use ArrayBufferSource, because we'll be creating an ArrayBuffer with OfflineAudioContext
let audioBufferSource: AudioBufferSource | null = null;
let audioBufferSource2: AudioBufferSource | null = null;
const audioBufferSource2: AudioBufferSource | null = null;
// Retrieve the first audio codec supported by this browser that can be contained in the output format
const audioCodec = await getFirstEncodableAudioCodec(output.format.getSupportedAudioCodecs(), {
@@ -160,11 +161,13 @@ const generateVideo = async () => {
});
output.addAudioTrack(audioBufferSource);
/*
audioBufferSource2 = new AudioBufferSource({
codec: audioCodec,
bitrate: QUALITY_HIGH,
});
output.addAudioTrack(audioBufferSource2, { languageCode: 'esp' });
*/
} else {
alert('Your browser doesn\'t support audio encoding, so we won\'t include audio in the output file.');
}
@@ -208,8 +211,8 @@ const generateVideo = async () => {
await audioBufferSource.add(audioBuffer);
audioBufferSource.close();
await audioBufferSource2!.add(audioBuffer);
audioBufferSource2!.close();
// await audioBufferSource2!.add(audioBuffer);
// audioBufferSource2!.close();
}
clearInterval(progressInterval);