{"record":{"id":"b758055b86eee947","repo":"remotion-dev/remotion","slug":"the-video-matting-model-model-returned-resu","errorCode":null,"errorMessage":"The video matting model \"${model}\" returned ${result.channels} channels instead of RGBA.","messagePattern":"The video matting model \"(.+?)\" returned (.+?) channels instead of RGBA\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/video-matting/src/load-video-matting-model.ts","lineNumber":243,"sourceCode":"\t\t\t\t\t\ttask: 'background-removal',\n\t\t\t\t\t\tmodel: transformerModel,\n\t\t\t\t\t\tprocessor: transformerProcessor,\n\t\t\t\t\t}) as unknown as TransformerPipeline;\n\t\t\t\t\tconst loadedTransformerPipeline = transformerPipeline;\n\n\t\t\t\t\tnotifyProgress(state, {\n\t\t\t\t\t\tstatus: 'ready',\n\t\t\t\t\t\tfile: null,\n\t\t\t\t\t\tprogress: 1,\n\t\t\t\t\t\tloadedBytes: totalBytes,\n\t\t\t\t\t\ttotalBytes,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst loadedPipeline: LoadedPipeline = {\n\t\t\t\t\t\trun: async (image) => {\n\t\t\t\t\t\t\tconst result = await loadedTransformerPipeline(image);\n\t\t\t\t\t\t\tif (result.channels !== 4) {\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`The video matting model \"${model}\" returned ${result.channels} channels instead of RGBA.`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst data =\n\t\t\t\t\t\t\t\tresult.data instanceof Uint8ClampedArray &&\n\t\t\t\t\t\t\t\tresult.data.buffer instanceof ArrayBuffer\n\t\t\t\t\t\t\t\t\t? (result.data as Uint8ClampedArray<ArrayBuffer>)\n\t\t\t\t\t\t\t\t\t: new Uint8ClampedArray(result.data);\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\twidth: result.width,\n\t\t\t\t\t\t\t\theight: result.height,\n\t\t\t\t\t\t\t\tchannels: 4,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdispose: () => loadedTransformerPipeline.dispose(),","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/video-matting/src/load-video-matting-model.ts#L225-L261","documentation":"The loaded transformers.js matting pipeline produced a tensor whose channel count is not 4 (RGBA). Video matting models must return alpha-augmented RGBA frames for compositing; anything else indicates the chosen model is not a matting model or its output format changed.","triggerScenarios":"Passing a model id (e.g. a segmentation or classification model) to loadVideoMattingModel / getOrCreateVideoMattingPipeline whose inference result has 1 or 3 channels.","commonSituations":"Typo or custom model id in the model option; a Hugging Face model swapped for a new revision with different output; using a non-RGBA model like a depth estimator with the matting API.","solutions":["Use one of the supported VIDEO_MATTING_MODELS (see models.ts) instead of a custom model id","If using a custom model, verify it outputs 4-channel RGBA (e.g. modify the post-processing to emit an alpha channel)","Pin the model revision that matches the tested output format"],"exampleFix":"// before\nconst model = 'Xenova/depth-anything-small';\n// after\nconst model = 'Xenova/modnet'; // a matting model returning RGBA","handlingStrategy":"validation","validationCode":"import {VIDEO_MATTING_MODELS} from '@remotion/video-matting';\nif (!VIDEO_MATTING_MODELS.includes(model)) {\n  throw new Error(`Unsupported matting model: ${model}`);\n}\n","typeGuard":"const isMattingModel = (m: string): m is VideoMattingModel =>\n  (VIDEO_MATTING_MODELS as readonly string[]).includes(m);\n","tryCatchPattern":"try {\n  await runPipeline(image);\n} catch (e) {\n  if ((e as Error).message.includes('channels instead of RGBA')) {\n    // fall back to a default supported matting model\n  }\n  throw e;\n}\n","preventionTips":["Only use models from VIDEO_MATTING_MODELS","Pin model revisions in production","Test custom models for 4-channel RGBA output before shipping"],"tags":["model","channels","rgba","transformers"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"b2f4e34732f3c6c222ea029413e22dc402218cd7","analyzedAt":"2026-09-09T13:27:51.281Z","contentChangedAt":"2026-09-09T13:27:51.281Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}