diff --git a/dev/demux.html b/dev/demux.html
index f4d059d..cff08c4 100644
--- a/dev/demux.html
+++ b/dev/demux.html
@@ -16,6 +16,72 @@
source
});
+ /*
+ const timestamps = [
+ 4.16,
+ 4.266666666666667,
+ 4.373333333333333,
+ 4.48,
+ 4.586666666666667,
+ 4.693333333333333,
+ 4.8,
+ 4.906666666666666,
+ 5.013333333333334,
+ 5.12,
+ 5.226666666666667,
+ 5.333333333333333,
+ 5.4399999999999995,
+ 5.546666666666667,
+ 5.653333333333333,
+ 5.76,
+ 5.866666666666666,
+ 5.973333333333333,
+ 6.08,
+ 6.186666666666666,
+ 6.293333333333333,
+ 6.4,
+ 6.506666666666666,
+ 6.613333333333333,
+ 6.72,
+ 6.826666666666666,
+ 6.933333333333334,
+ 7.039999999999999,
+ 7.1466666666666665,
+ 7.253333333333333
+ ];
+ */
+ const timestamps = [];
+ const videoTrack = await input.getPrimaryVideoTrack();
+
+ const packetSink = new Metamuxer.EncodedPacketSink(videoTrack);
+ for await (const packet of packetSink.packets()) {
+ if (packet.timestamp >= 1) {
+ break;
+ }
+
+ timestamps.push(packet.timestamp);
+ }
+
+ timestamps.sort((a, b) => a-b)
+
+ console.log(timestamps);
+ //return;
+ /*
+ const sink = new Metamuxer.EncodedPacketSink(videoTrack);
+ for await (const packet of sink.packets()) {
+ console.log(packet.sequenceNumber);
+ }
+ */
+
+
+ const sink = new Metamuxer.CanvasSink(videoTrack, { width: 320 });
+
+ for await (const wrappedCanvas of sink.canvasesAtTimestamps(timestamps)) {
+ console.log(wrappedCanvas);
+ }
+
+
+ /*
const output = new Metamuxer.Output({
format: new Metamuxer.Mp3OutputFormat(),
target: new Metamuxer.BufferTarget()
@@ -49,6 +115,7 @@
console.log(output.target.buffer)
download(new Blob([output.target.buffer]), 'converted.mp3');
+ */
/*
diff --git a/src/media-sink.ts b/src/media-sink.ts
index dd99777..7e78e7f 100644
--- a/src/media-sink.ts
+++ b/src/media-sink.ts
@@ -526,6 +526,8 @@ export abstract class BaseMediaSampleSink<
continue;
}
+ // console.log('target', targetPacket);
+
const keyPacket = await packetSink.getKeyPacket(timestamp);
if (!keyPacket) {
pushToQueue(null);
@@ -533,15 +535,17 @@ export abstract class BaseMediaSampleSink<
}
if (lastPacket && targetPacket.sequenceNumber < lastPacket.sequenceNumber) {
- // We're going back in time with this one, let's flush and reset to an clean state
+ // console.log('FLUSH?', lastPacket, targetPacket.sequenceNumber, lastPacket.sequenceNumber);
+ // We're going back in time with this one, let's flush and reset to a clean state
await decoder.flush();
timestampsOfInterest.length = 0;
}
if (
lastKeyPacket
- && keyPacket.sequenceNumber === lastKeyPacket.sequenceNumber
- && targetPacket.timestamp >= lastPacket!.timestamp
+ && keyPacket.sequenceNumber === lastKeyPacket.sequenceNumber // => they're the same packet
+ // && targetPacket.timestamp >= lastPacket!.timestamp
+ && targetPacket.sequenceNumber >= lastPacket!.sequenceNumber
) {
assert(lastPacket);
@@ -558,6 +562,7 @@ export abstract class BaseMediaSampleSink<
timestampsOfInterest.push(targetPacket.timestamp);
}
} else {
+ // console.log('==== RESET');
// The key packet has changed
lastKeyPacket = keyPacket;
lastPacket = keyPacket;
diff --git a/todo.txt b/todo.txt
index 0bb2534..adfe1d4 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,3 +1,4 @@
- https://github.com/Vanilagy/mp4-muxer/issues/83 tell him it's possible now
- textsubtitlesource, chunked piping
-- More efficient MP3 loading when reading sequentially
\ No newline at end of file
+- More efficient MP3 loading when reading sequentially
+- toCanvasImageSource might return a new videoframe; how to handle this?
\ No newline at end of file