Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(exporter): add codec normalization for bare avc1/h264 and logging

FabLrccae71ed49c56
diff --git a/src/lib/exporter/streamingDecoder.ts b/src/lib/exporter/streamingDecoder.ts
index c3bca3c49..8cf0257b8 100644
--- a/src/lib/exporter/streamingDecoder.ts
+++ b/src/lib/exporter/streamingDecoder.ts
@@ -302,9 +302,12 @@ export class StreamingVideoDecoder {
const decoderConfig = await this.demuxer.getDecoderConfig("video");
- // web-demuxer may return a bare "av01" for AV1 in WebM containers when the
- // extradata isn't in the expected ISOBMFF format. WebCodecs requires the
- // full parametrized form (e.g. "av01.0.05M.08").
+ console.log("[StreamingVideoDecoder] decoderConfig.codec:", decoderConfig.codec);
+ console.log("[StreamingVideoDecoder] decoderConfig.description:", decoderConfig.description);
+
+ // web-demuxer may return bare four-character code strings ("av01", "vp08",
+ // "vp09", "avc1") that WebCodecs rejects. Normalize them to the short or
+ // full parametrized forms that VideoDecoder accepts.
if (/^av01$/i.test(decoderConfig.codec)) {
decoderConfig.codec = buildAV1CodecString(
decoderConfig.description as BufferSource | undefined,
@@ -318,9 +321,19 @@ export class StreamingVideoDecoder {
decoderConfig.codec = "vp9";
}
+ if (/^avc1$/i.test(decoderConfig.codec)) {
+ decoderConfig.codec = "avc1.640033";
+ }
+ if (/^h264$/i.test(decoderConfig.codec)) {
+ decoderConfig.codec = "avc1.640033";
+ }
+
const codec = decoderConfig.codec.toLowerCase();
const shouldPreferSoftwareDecode =
- codec.includes("av01") || codec.includes("av1") || codec.includes("vp09");
+ codec.includes("av01") ||
+ codec.includes("av1") ||
+ codec.includes("vp09") ||
+ codec.includes("vp9");
const segments = this.splitBySpeed(
this.computeSegments(this.metadata.duration, trimRegions),
speedRegions,
@@ -351,6 +364,10 @@ export class StreamingVideoDecoder {
}
},
error: (e: DOMException) => {
+ console.warn(
+ `[StreamingVideoDecoder] decoder error for codec "${decoderConfig.codec}":`,
+ e.message,
+ );
decodeError = new Error(`VideoDecoder error: ${e.message}`);
if (frameResolve) {
const resolve = frameResolve;
@@ -367,6 +384,17 @@ export class StreamingVideoDecoder {
: decoderConfig;
try {
+ const support = await VideoDecoder.isConfigSupported(preferredDecoderConfig);
+ console.log(
+ `[StreamingVideoDecoder] isConfigSupported for "${preferredDecoderConfig.codec}":`,
+ support.supported,
+ );
+ if (!support.supported) {
+ throw new DOMException(
+ `Unsupported codec: ${preferredDecoderConfig.codec}`,
+ "NotSupportedError",
+ );
+ }
this.decoder.configure(preferredDecoderConfig);
} catch (error) {
if (!shouldPreferSoftwareDecode) {