Skip to content

🎥 Make videos programmatically with React

perfect audio!

JonnyBurgere4348e89596d
diff --git a/packages/video/src/extract-frame.ts b/packages/video/src/extract-frame.ts
index 2271fa93c3..42c2c4c65e 100644
--- a/packages/video/src/extract-frame.ts
+++ b/packages/video/src/extract-frame.ts
@@ -52,7 +52,7 @@ export const extractAudio = async ({
sinkPromise[src] = getSinks(src);
}
- const {audio, actualMatroskaTimestamps} = await sinkPromise[src];
+ const {audio, actualMatroskaTimestamps, isMatroska} = await sinkPromise[src];
if (audio === null) {
return null;
@@ -66,8 +66,12 @@ export const extractAudio = async ({
// and then discard it,
const extraThreshold = 1 / fps;
+ // Matroska timestamps are not accurate unless we start from the beginning
+ // So for matroska, we need to decode all samples :(
+
+ // https://github.com/Vanilagy/mediabunny/issues/105
const sampleIterator = audio.sampleSink.samples(
- timeInSeconds - extraThreshold,
+ isMatroska ? 0 : timeInSeconds - extraThreshold,
timeInSeconds + durationInSeconds + extraThreshold,
);
const samples: AudioSample[] = [];
diff --git a/packages/video/src/get-frames-since-keyframe.ts b/packages/video/src/get-frames-since-keyframe.ts
index 82967e97a4..a3d4a0e797 100644
--- a/packages/video/src/get-frames-since-keyframe.ts
+++ b/packages/video/src/get-frames-since-keyframe.ts
@@ -38,6 +38,7 @@ export const getSinks = async (src: string) => {
}
: null,
actualMatroskaTimestamps: rememberActualMatroskaTimestamps(isMatroska),
+ isMatroska,
};
};