fix: surface unsupported video codec on import, fix Input leaks

This commit is contained in:
Maze Winther
2026-04-25 02:46:31 +02:00
parent cceb835a84
commit 0dffefdd59
4 changed files with 166 additions and 145 deletions
+9 -5
View File
@@ -7,6 +7,7 @@ import {
} from "mediabunny";
interface VideoSinkData {
input: Input;
sink: CanvasSink;
iterator: AsyncGenerator<WrappedCanvas, void, unknown> | null;
currentFrame: WrappedCanvas | null;
@@ -262,12 +263,12 @@ export class VideoCache {
mediaId: string;
file: File;
}): Promise<void> {
try {
const input = new Input({
source: new BlobSource(file),
formats: ALL_FORMATS,
});
const input = new Input({
source: new BlobSource(file),
formats: ALL_FORMATS,
});
try {
const videoTrack = await input.getPrimaryVideoTrack();
if (!videoTrack) {
throw new Error("No video track found");
@@ -284,6 +285,7 @@ export class VideoCache {
});
this.sinks.set(mediaId, {
input,
sink,
iterator: null,
currentFrame: null,
@@ -293,6 +295,7 @@ export class VideoCache {
prefetchPromise: null,
});
} catch (error) {
input.dispose();
console.error(`Failed to initialize video sink for ${mediaId}:`, error);
throw error;
}
@@ -305,6 +308,7 @@ export class VideoCache {
void sinkData.iterator.return();
}
sinkData.input.dispose();
this.sinks.delete(mediaId);
}