mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Fix atTimestamps iterator
This commit is contained in:
+21
-15
@@ -40,6 +40,15 @@
|
|||||||
source
|
source
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const videoTrack = await input.getPrimaryVideoTrack();
|
||||||
|
const sink = new Metamuxer.VideoFrameSink(videoTrack);
|
||||||
|
|
||||||
|
for await (const thing of sink.framesAtTimestamps([0.2, 1, 2, 423])) {
|
||||||
|
console.log(thing)
|
||||||
|
}
|
||||||
|
console.log("Done")
|
||||||
|
|
||||||
|
/*
|
||||||
//const videoTrack = await input.getPrimaryVideoTrack();
|
//const videoTrack = await input.getPrimaryVideoTrack();
|
||||||
//console.log(await videoTrack.computeSampleStats());
|
//console.log(await videoTrack.computeSampleStats());
|
||||||
//return;
|
//return;
|
||||||
@@ -71,26 +80,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
//for await (const sample of sink.samples()) {
|
||||||
for await (const sample of sink.samples()) {
|
// //console.log(sample.timestamp);
|
||||||
//console.log(sample.timestamp);
|
// //sample.timestamp *= 2;
|
||||||
//sample.timestamp *= 2;
|
// //console.log(sample);
|
||||||
//console.log(sample);
|
// //console.log(sample)
|
||||||
//console.log(sample)
|
// await sampleSource.digest(sample, { decoderConfig });
|
||||||
await sampleSource.digest(sample, { decoderConfig });
|
//}
|
||||||
}
|
|
||||||
*/
|
|
||||||
for await (const { data, timestamp } of new Metamuxer.AudioDataSink(audioTrack).data()) {
|
for await (const { data, timestamp } of new Metamuxer.AudioDataSink(audioTrack).data()) {
|
||||||
//console.log("wow", data.timestamp);
|
//console.log("wow", data.timestamp);
|
||||||
//console.log(sample)
|
//console.log(sample)
|
||||||
await audioDataSource.digest(data);
|
await audioDataSource.digest(data);
|
||||||
}
|
}
|
||||||
/*
|
//for await (const sample of new Metamuxer.EncodedVideoSampleSink(videoTrack).samples()) {
|
||||||
for await (const sample of new Metamuxer.EncodedVideoSampleSink(videoTrack).samples()) {
|
// //console.log(sample)
|
||||||
//console.log(sample)
|
// await videoSampleSource.digest(sample, { decoderConfig: videoDecoderConfig });
|
||||||
await videoSampleSource.digest(sample, { decoderConfig: videoDecoderConfig });
|
//}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
await output.finalize();
|
await output.finalize();
|
||||||
|
|
||||||
@@ -107,6 +112,7 @@
|
|||||||
download(new Blob([target.buffer]), 'converted.wav');
|
download(new Blob([target.buffer]), 'converted.wav');
|
||||||
|
|
||||||
document.body.textContent = performance.now() - start;
|
document.body.textContent = performance.now() - start;
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const input2 = new Metamuxer.Input({
|
const input2 = new Metamuxer.Input({
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ export const AUDIO_CODECS = [
|
|||||||
'vorbis',
|
'vorbis',
|
||||||
'flac',
|
'flac',
|
||||||
...PCM_CODECS,
|
...PCM_CODECS,
|
||||||
] as const; // TODO add the rest
|
] as const;
|
||||||
/** @public */
|
/** @public */
|
||||||
export const SUBTITLE_CODECS = ['webvtt'] as const; // TODO add the rest
|
export const SUBTITLE_CODECS = ['webvtt'] as const; // TODO add the rest
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -392,7 +392,10 @@ export abstract class BaseMediaFrameSink<
|
|||||||
}
|
}
|
||||||
|
|
||||||
let frameUsed = false;
|
let frameUsed = false;
|
||||||
while (samplesOfInterest.length > 0 && samplesOfInterest[0] === wrappedFrame.sample) {
|
while (
|
||||||
|
samplesOfInterest.length > 0
|
||||||
|
&& samplesOfInterest[0]!.is(wrappedFrame.sample as EncodedVideoSample & EncodedAudioSample)
|
||||||
|
) {
|
||||||
pushToQueue(this._duplicateFrame(wrappedFrame));
|
pushToQueue(this._duplicateFrame(wrappedFrame));
|
||||||
samplesOfInterest.shift();
|
samplesOfInterest.shift();
|
||||||
frameUsed = true;
|
frameUsed = true;
|
||||||
|
|||||||
@@ -42,6 +42,15 @@ export class EncodedVideoSample {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is(otherSample: EncodedVideoSample) {
|
||||||
|
return (
|
||||||
|
this.type === otherSample.type
|
||||||
|
&& this.timestamp === otherSample.timestamp
|
||||||
|
&& this.duration === otherSample.duration
|
||||||
|
&& this.byteLength === otherSample.byteLength
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static fromEncodedVideoChunk(chunk: EncodedVideoChunk) {
|
static fromEncodedVideoChunk(chunk: EncodedVideoChunk) {
|
||||||
if (typeof EncodedVideoChunk === 'undefined') {
|
if (typeof EncodedVideoChunk === 'undefined') {
|
||||||
throw new Error('Your browser does not support EncodedVideoChunk.');
|
throw new Error('Your browser does not support EncodedVideoChunk.');
|
||||||
@@ -98,6 +107,15 @@ export class EncodedAudioSample {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is(otherSample: EncodedAudioSample) {
|
||||||
|
return (
|
||||||
|
this.type === otherSample.type
|
||||||
|
&& this.timestamp === otherSample.timestamp
|
||||||
|
&& this.duration === otherSample.duration
|
||||||
|
&& this.byteLength === otherSample.byteLength
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static fromEncodedAudioChunk(chunk: EncodedAudioChunk) {
|
static fromEncodedAudioChunk(chunk: EncodedAudioChunk) {
|
||||||
if (typeof EncodedAudioChunk === 'undefined') {
|
if (typeof EncodedAudioChunk === 'undefined') {
|
||||||
throw new Error('Your browser does not support EncodedAudioChunk.');
|
throw new Error('Your browser does not support EncodedAudioChunk.');
|
||||||
|
|||||||
Reference in New Issue
Block a user