Fix async race condition bug

This commit is contained in:
Vanilagy
2025-05-08 16:23:07 +02:00
parent 94b797e227
commit 865fdcf110
3 changed files with 49 additions and 12 deletions
+6 -6
View File
@@ -21,7 +21,7 @@
chunked: true,
chunkSize: 2**20
});
const outputFormat = new Metamuxer.OggOutputFormat();
const outputFormat = new Metamuxer.WavOutputFormat();
const button = document.createElement('button');
button.textContent = 'Cancel';
@@ -77,10 +77,10 @@
//width: 200,
//height: 100,
},
trim: {
start: 0,
end: 30
},
//trim: {
// start: 0,
// end: 30
//},
computeProgress: true
});
console.log(conversion);
@@ -108,7 +108,7 @@
document.body.append(video);
video.play();
//download(new Blob([target.buffer]), 'converted' + outputFormat.fileExtension);
download(new Blob([target.buffer]), 'converted' + outputFormat.fileExtension);
function download(blob, filename) {
const url = URL.createObjectURL(blob);
+25
View File
@@ -43,6 +43,7 @@
format = new Metamuxer.OggOutputFormat();
format = new Metamuxer.Mp4OutputFormat({ fastStart: 'fragmented', minimumFragmentDuration: 2 });
format = new Metamuxer.MkvOutputFormat({ minimumClusterDuration: 2 });
format = new Metamuxer.WavOutputFormat();
let target = new Metamuxer.BufferTarget();
/*
@@ -57,6 +58,30 @@
let output = new Metamuxer.Output({ format, target });
let sourcy = new Metamuxer.AudioBufferSource({
codec: 'pcm-s16',
bitrate: Metamuxer.QUALITY_HIGH
});
output.addAudioTrack(sourcy);
await output.start();
for (let i = 0; i < 1000; i++) {
let buf = new AudioBuffer({
length: 1024,
sampleRate: 48000,
numberOfChannels: 2
});
sourcy.add(buf);
}
console.log("Done")
await output.finalize();
await new Promise(() => {});
/*
let videoSource = new Metamuxer.EncodedVideoChunkSource('avc');
output.addTrack(videoSource);