{"record":{"id":"1d3ebd75bfbec5e9","repo":"remotion-dev/remotion","slug":"a-numeric-bitrate-must-be-a-positive-integer","errorCode":null,"errorMessage":"A numeric bitrate must be a positive integer.","messagePattern":"A numeric bitrate must be a positive integer\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/video-matting/src/video-matting-quality.ts","lineNumber":20,"sourceCode":"\nexport const VIDEO_MATTING_QUALITIES = [\n\t'very-low',\n\t'low',\n\t'medium',\n\t'high',\n\t'very-high',\n] as const;\n\nexport type VideoMattingQuality = (typeof VIDEO_MATTING_QUALITIES)[number];\n\nexport type VideoMattingBitrate = number | VideoMattingQuality;\n\nexport const resolveVideoMattingQuality = (\n\tvalue: VideoMattingBitrate,\n): Quality => {\n\tif (typeof value === 'number') {\n\t\tif (!Number.isInteger(value) || value <= 0) {\n\t\t\tthrow new TypeError('A numeric bitrate must be a positive integer.');\n\t\t}\n\n\t\treturn new Quality({bitrate: value});\n\t}\n\n\tif (!VIDEO_MATTING_QUALITIES.includes(value)) {\n\t\tthrow new TypeError(\n\t\t\t`The bitrate quality must be one of ${VIDEO_MATTING_QUALITIES.join(', ')}.`,\n\t\t);\n\t}\n\n\treturn new Quality({quality: value, preferBitrate: true});\n};\n","sourceCodeStart":2,"sourceCodeEnd":34,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/video-matting/src/video-matting-quality.ts#L2-L34","documentation":"resolveVideoMattingQuality converts a VideoMattingBitrate into a Quality. When the caller passes a number, it must be a positive integer bitrate in bits per second; non-integers, zero, negative values, NaN or Infinity are rejected with a TypeError. This ensures the underlying encoder receives a valid bitrate.","triggerScenarios":"Passing a number bitrate like 0, -5000, 3.5, NaN or Infinity to resolveVideoMattingQuality — typically via a videoMatting quality/bitrate option in the render or component API.","commonSituations":"Computing a bitrate dynamically (e.g. width * height * factor) producing a float, a config value of 0 meaning 'unset' being passed through, or parsing a user-supplied string with parseFloat instead of parseInt.","solutions":["Pass a positive integer, e.g. 4_000_000 instead of 4e6/3 or 0","Round and validate dynamic bitrates: Math.round(computed) and check > 0 before calling","Use a named quality preset ('low' | 'medium' | 'high') instead of a raw number if unsure","Fix config parsing so unset/0 values fall back to a default rather than being passed as bitrate"],"exampleFix":"// before\nconst q = resolveVideoMattingQuality(bitrateFromConfig); // 0 or 3.5\n// after\nconst bitrate = Math.round(Number(bitrateFromConfig));\nif (!Number.isInteger(bitrate) || bitrate <= 0) throw new Error('Invalid bitrate in config');\nconst q = resolveVideoMattingQuality(bitrate);","handlingStrategy":"validation","validationCode":"const isValidBitrate = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isInteger(v) && v > 0;\nif (!isValidBitrate(bitrate)) throw new TypeError(`Invalid bitrate: ${bitrate}`);","typeGuard":"const isNumericBitrate = (v: VideoMattingBitrate): v is number =>\n  typeof v === 'number';\nconst isValidNumericBitrate = (v: VideoMattingBitrate): v is number =>\n  typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":"try {\n  const quality = resolveVideoMattingQuality(bitrate);\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('positive integer')) {\n    return resolveVideoMattingQuality(4_000_000); // sensible default\n  }\n  throw err;\n}","preventionTips":["Round computed bitrates with Math.round before passing","Treat 0/undefined config values as 'use default', never as bitrate","Use parseInt (not parseFloat) when parsing bitrate strings","Centralize bitrate validation in one config-parsing step"],"tags":["video-matting","bitrate","validation","typescript"],"backgroundTag":"invalid-argument-value","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"}