Fix encodability checks throwing due to unsupported config feature set; now counts as not supported (fixes #456)

This commit is contained in:
Vanilagy
2026-08-06 11:07:15 +02:00
parent ce10bb774a
commit 4e4e6eed0c
2 changed files with 32 additions and 10 deletions
+14 -4
View File
@@ -1117,8 +1117,13 @@ export const canEncodeVideo = async (
} }
for (const { config, quantizer } of candidates) { for (const { config, quantizer } of candidates) {
const support = await VideoEncoder.isConfigSupported(config); try {
if (!support.supported) { const support = await VideoEncoder.isConfigSupported(config);
if (!support.supported) {
continue;
}
} catch {
// Can type-error when unknown config features are used
continue; continue;
} }
@@ -1245,8 +1250,13 @@ export const canEncodeAudio = async (
return false; return false;
} }
const support = await AudioEncoder.isConfigSupported(encoderConfig); try {
return support.supported === true; const support = await AudioEncoder.isConfigSupported(encoderConfig);
return support.supported === true;
} catch {
// Can type-error when unknown config features are used
return false;
}
})(); })();
canEncodeAudioMemo.set(key, promise); canEncodeAudioMemo.set(key, promise);
+18 -6
View File
@@ -705,10 +705,14 @@ class VideoEncoderWrapper {
); );
} }
const support = await VideoEncoder.isConfigSupported(candidateConfig); try {
if (support.supported) { const support = await VideoEncoder.isConfigSupported(candidateConfig);
selected = candidate; if (support.supported) {
break; selected = candidate;
break;
}
} catch {
// Not supported
} }
} }
@@ -2209,8 +2213,16 @@ class AudioEncoderWrapper {
throw new Error('AudioEncoder is not supported by this browser.'); throw new Error('AudioEncoder is not supported by this browser.');
} }
const support = await AudioEncoder.isConfigSupported(encoderConfig); let supported: boolean;
if (!support.supported) {
try {
const support = await AudioEncoder.isConfigSupported(encoderConfig);
supported = support.supported ?? false;
} catch {
supported = false;
}
if (!supported) {
throw new Error( throw new Error(
`This specific encoder configuration (${encoderConfig.codec}, ${encoderConfig.bitrate} bps,` `This specific encoder configuration (${encoderConfig.codec}, ${encoderConfig.bitrate} bps,`
+ ` ${encoderConfig.numberOfChannels} channels, ${encoderConfig.sampleRate} Hz) is not` + ` ${encoderConfig.numberOfChannels} channels, ${encoderConfig.sampleRate} Hz) is not`