mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Allow for out-of-presentation-order chunks, enabling P and B frames
This commit is contained in:
+32
-3
@@ -36,17 +36,45 @@
|
||||
canvas.height = 720;
|
||||
const context = canvas.getContext('2d');
|
||||
|
||||
let format = new Metamuxer.WebMOutputFormat(); //new Metamuxer.Mp4OutputFormat({ fastStart: false });
|
||||
let format = new Metamuxer.MkvOutputFormat();// new Metamuxer.Mp4OutputFormat({ fastStart: false });
|
||||
let target = new Metamuxer.ArrayBufferTarget();
|
||||
|
||||
let output = new Metamuxer.Output({ format, target });
|
||||
|
||||
let videoSource = new Metamuxer.EncodedVideoChunkSource('avc');
|
||||
output.addTrack(videoSource);
|
||||
|
||||
output.start();
|
||||
|
||||
const timestamps = [0, 0.5, 0.25, 0.75, 1, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 2];
|
||||
for (const timestamp of timestamps) {
|
||||
const encodedVideoChunk = new EncodedVideoChunk({
|
||||
type: timestamp % 1 === 0 ? 'key' : 'delta',
|
||||
timestamp: 1e6 * timestamp,
|
||||
duration: 1e6 * 0.25,
|
||||
data: new Uint8Array(1024)
|
||||
});
|
||||
videoSource.digest(encodedVideoChunk, {
|
||||
decoderConfig: {
|
||||
codedWidth: 64,
|
||||
codedHeight: 64,
|
||||
description: new Uint8Array(64)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await output.finalize();
|
||||
|
||||
console.log(target);
|
||||
download(new Blob([target.buffer]), 'test.mkv');
|
||||
|
||||
/*
|
||||
let videoSource = new Metamuxer.CanvasSource(canvas, {
|
||||
codec: 'avc',
|
||||
bitrate: 1e6
|
||||
});
|
||||
let audioSource = new Metamuxer.AudioBufferSource({
|
||||
codec: 'opus',
|
||||
codec: 'aac',
|
||||
bitrate: 128e3,
|
||||
});
|
||||
|
||||
@@ -72,5 +100,6 @@
|
||||
await output.finalize();
|
||||
|
||||
console.log(target);
|
||||
download(new Blob([target.buffer]), 'test.webm');
|
||||
download(new Blob([target.buffer]), 'test.mp4');
|
||||
*/
|
||||
</script>
|
||||
Reference in New Issue
Block a user