{"record":{"id":"c23bd105510f10d2","repo":"remotion-dev/remotion","slug":"outputs-layer-outputwritable-must-not-already-b","errorCode":null,"errorMessage":"outputs.${layer}.outputWritable must not already be locked.","messagePattern":"outputs\\.(.+?)\\.outputWritable must not already be locked\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/video-matting/src/separate-video-layers.ts","lineNumber":148,"sourceCode":"\t\toutput.outputWritable !== undefined\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`outputs.${layer} cannot specify both outputTarget and outputWritable.`,\n\t\t);\n\t}\n\n\tif (output.outputWritable !== undefined) {\n\t\tif (\n\t\t\ttypeof WritableStream === 'undefined' ||\n\t\t\t!(output.outputWritable instanceof WritableStream)\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`outputs.${layer}.outputWritable must be a WritableStream.`,\n\t\t\t);\n\t\t}\n\n\t\tif (output.outputWritable.locked) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`outputs.${layer}.outputWritable must not already be locked.`,\n\t\t\t);\n\t\t}\n\t}\n};\n\nconst validateOptions = (options: SeparateVideoLayersOptions) => {\n\tif (!options || typeof options !== 'object') {\n\t\tthrow new TypeError('separateVideoLayers() expects an options object.');\n\t}\n\n\tconst isBlob = typeof Blob !== 'undefined' && options.src instanceof Blob;\n\tconst isUrl = options.src instanceof URL;\n\tif (typeof options.src !== 'string' && !isUrl && !isBlob) {\n\t\tthrow new TypeError('src must be a string, URL, or Blob.');\n\t}\n\n\tif (typeof options.src === 'string' && options.src.length === 0) {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/video-matting/src/separate-video-layers.ts#L130-L166","documentation":"A WritableStream can be locked (e.g. via getWriter() or getReader on its pipe counterpart). separateVideoLayers() needs exclusive access to write encoded output, so passing an already-locked stream is rejected with this TypeError.","triggerScenarios":"Calling output.outputWritable.getWriter() before passing the stream; passing the writable side of a TransformStream that already has a writer attached; piping the stream elsewhere before handing it to separateVideoLayers().","commonSituations":"Acquiring a writer for logging/teeing and forgetting to releaseLock(); reusing the same stream across two pipeline stages; sharing one stream between base and foreground outputs (see sibling error).","solutions":["Do not call getWriter() on the stream you pass, or call writer.releaseLock() before invoking separateVideoLayers()","Pass a fresh or TransformStream-derived writable that no other consumer has locked","Create two separate streams if you need both base and foreground output"],"exampleFix":"// before\nconst writer = writable.getWriter();\nawait separateVideoLayers({ src, outputs: { base: { outputWritable: writable } } });\n// after\nconst writer = writable.getWriter();\nwriter.releaseLock();\nawait separateVideoLayers({ src, outputs: { base: { outputWritable: writable } } });","handlingStrategy":"validation","validationCode":"function assertNotLocked(s) { if (s && s.locked) throw new TypeError('outputWritable is already locked; release the writer first'); }","typeGuard":"const isUnlockedWritable = (v) => v instanceof WritableStream && !v.locked;","tryCatchPattern":"try { await separateVideoLayers(opts); } catch (e) { if (e instanceof TypeError && e.message.includes('must not already be locked')) { writer?.releaseLock(); /* retry */ } else throw e; }","preventionTips":["Avoid getWriter() on streams you hand to the library","Call releaseLock() as soon as you're done writing","Never share one stream across pipeline consumers"],"tags":["writable-stream","stream-state","validation"],"backgroundTag":"invalid-state-transition","analyzedSha":"b2f4e34732f3c6c222ea029413e22dc402218cd7","analyzedAt":"2026-09-09T13:27:51.281Z","contentChangedAt":"2026-09-09T13:27:51.281Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}