Add Matroska demuxer

This commit is contained in:
Vanilagy
2025-01-11 19:39:01 +01:00
parent fbe084d721
commit c38c285eab
10 changed files with 2031 additions and 256 deletions
+6 -6
View File
@@ -38,9 +38,9 @@
canvas.height = 720;
const context = canvas.getContext('2d');
let format = new Metamuxer.WebMOutputFormat({ streamable: true });
format = new Metamuxer.Mp4OutputFormat({ fastStart: false }); // new Metamuxer.MkvOutputFormat();// new Metamuxer.Mp4OutputFormat({ fastStart: false });
let target = new Metamuxer.ArrayBufferTarget();
let format = new Metamuxer.WebMOutputFormat({ streamable: false });
//format = new Metamuxer.Mp4OutputFormat({ fastStart: false }); // new Metamuxer.MkvOutputFormat();// new Metamuxer.Mp4OutputFormat({ fastStart: false });
let target = new Metamuxer.BufferTarget();
/*
target = new Metamuxer.StreamTarget(new WritableStream({
@@ -84,7 +84,7 @@
*/
let videoSource = new Metamuxer.CanvasSource(canvas, {
codec: 'avc',
codec: 'vp9',
bitrate: 1e6
});
let audioSource = new Metamuxer.AudioBufferSource({
@@ -95,7 +95,7 @@
output.addVideoTrack(videoSource);
output.addAudioTrack(audioSource);
output.addSubtitleTrack(subtitleSource);
//output.addSubtitleTrack(subtitleSource);
output.start();
@@ -174,5 +174,5 @@ Testing... <00:17.350>One... <00:18.125>Two...
await output.finalize();
console.log(target);
download(new Blob([target.buffer]), 'test.mp4');
download(new Blob([target.buffer]), 'test.webm');
</script>
+17 -2
View File
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<input type="file" accept="video/mp4,video/quicktime,audio/x-m4a,video/x-m4v,audio/wav">
<input type="file" accept="video/mp4,video/quicktime,audio/x-m4a,video/x-m4v,audio/wav,video/webm">
<div id="player"
style="display: none; flex-direction: column; align-items: center;
@@ -35,6 +35,7 @@ fileInput.style.display = 'none';
const audioContext = new AudioContext();
const source = new Metamuxer.BlobSource(file);
const input = new Metamuxer.Input({
formats: Metamuxer.ALL_FORMATS,
source
@@ -43,7 +44,21 @@ const input = new Metamuxer.Input({
console.log(await input.getMimeType())
let videoTrack = await input.getPrimaryVideoTrack();
let audioTrack = await input.getPrimaryAudioTrack();
let audioTrack = await input.getPrimaryAudioTrack();
//console.log(await videoTrack.computeDuration());
//await new Promise(() => {});
/*
const sink = new Metamuxer.EncodedVideoSampleSink(videoTrack);
for await (const sample of sink.samples()) {
console.log(sample);
await new Promise(resolve => setTimeout(resolve, 100));
}
await new Promise(() => {});
*/
if (!(await videoTrack?.canDecode())) {
videoTrack = null;