fix: better mediabunny init status

This commit is contained in:
Maya 2026-03-11 16:33:40 +03:00
parent c26ae458b1
commit f26cd7e615
No known key found for this signature in database
3 changed files with 45 additions and 10 deletions

View File

@ -341,7 +341,8 @@
"magick": "Error in Magick worker, image conversion may not work as expected.",
"ffmpeg": "Error loading FFmpeg, some features may not work as expected.",
"pandoc": "Error loading Pandoc worker, document conversion may not work as expected.",
"mediabunny": "Error loading Mediabunny worker, video conversion may not work as expected.",
"mediabunny_init": "Error loading Mediabunny, video conversion may not work as expected.",
"mediabunny_webcodecs": "Some WebCodecs APIs are not supported in this browser, video conversion may not work as expected.",
"no_audio": "No audio stream found.",
"invalid_rate": "Invalid sample rate specified: {rate}Hz",
"file_too_large": "This file exceeds the {limit}GB browser / device limit. Try Firefox or Safari to convert this large file, which typically have higher limits."

View File

@ -107,7 +107,7 @@ export class FFmpegConverter extends Converter {
this.status = "ready";
})();
} catch (err) {
error(["converters", this.name], `Error loading ffmpeg: ${err}`);
this.error(`Error loading ffmpeg: ${err}`);
this.status = "error";
ToastManager.add({
type: "error",

View File

@ -225,14 +225,50 @@ export class MediabunnyConverter extends Converter {
// additional mediabunny coders
// currently the official ones -- maybe add our own in the future
this.initializeCodecs();
// checks if mediabunny and webcodecs are initialized and supported
this.checkStatus();
}
// TODO: don't know how to check if mediabunny is ready/actually supported rn, maybe test smol conversion or run some other method? shrug
if (typeof Conversion === "undefined") {
this.status = "not-ready";
this.error("Mediabunny failed to load");
private checkStatus() {
const mediabunnyInitialized = canEncodeAudio("pcm-s16");
const webCodecsVideoDecode = "VideoDecoder" in globalThis;
const webCodecsVideoEncode = "VideoEncoder" in globalThis;
const webCodecsAudioDecode = "AudioDecoder" in globalThis;
const webCodecsAudioEncode = "AudioEncoder" in globalThis;
this.log(
`Supported WebCodecs APIs: VideoDecoder: ${webCodecsVideoDecode}, VideoEncoder: ${webCodecsVideoEncode}, AudioDecoder: ${webCodecsAudioDecode}, AudioEncoder: ${webCodecsAudioEncode}`,
);
if (!mediabunnyInitialized) {
this.error("Mediabunny failed to initialize");
ToastManager.add({
type: "error",
message: m["workers.errors.mediabunny"](),
durations: {
stay: 10000,
},
});
this.status = "error";
} else if (
!webCodecsVideoDecode ||
!webCodecsVideoEncode ||
!webCodecsAudioDecode ||
!webCodecsAudioEncode
) {
this.error("WebCodecs API support incomplete");
ToastManager.add({
type: "error",
message: m["workers.errors.mediabunny_webcodecs"](),
durations: {
stay: 10000,
},
});
this.status = "partially-ready";
} else {
this.status = "ready";
this.log("Mediabunny loaded successfully");
}
}
@ -527,9 +563,7 @@ export class MediabunnyConverter extends Converter {
public async cancel(input: VertFile): Promise<void> {
const conversion = this.activeConversions.get(input.id);
if (!conversion) {
this.error(
`no active conversion found for file ${input.name}`,
);
this.error(`no active conversion found for file ${input.name}`);
return;
}