{"record":{"id":"83cbd3b283c1f9df","repo":"remotion-dev/remotion","slug":"you-passed-in-a-function-to-the-volume-prop-but-it","errorCode":null,"errorMessage":"You passed in a function to the volume prop but it returned NaN for frame ${frame}.","messagePattern":"You passed in a function to the volume prop but it returned NaN for frame (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/volume-prop.ts","lineNumber":28,"sourceCode":"\tmediaVolume: number;\n}): number => {\n\tif (typeof volume === 'number') {\n\t\treturn volume * mediaVolume;\n\t}\n\n\tif (typeof volume === 'undefined') {\n\t\treturn Number(mediaVolume);\n\t}\n\n\tconst evaluated = volume(frame) * mediaVolume;\n\tif (typeof evaluated !== 'number') {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a a function to the volume prop but it did not return a number but a value of type ${typeof evaluated} for frame ${frame}`,\n\t\t);\n\t}\n\n\tif (Number.isNaN(evaluated)) {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a function to the volume prop but it returned NaN for frame ${frame}.`,\n\t\t);\n\t}\n\n\tif (!Number.isFinite(evaluated)) {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a function to the volume prop but it returned a non-finite number for frame ${frame}.`,\n\t\t);\n\t}\n\n\treturn Math.max(0, evaluated);\n};\n","sourceCodeStart":10,"sourceCodeEnd":41,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/volume-prop.ts#L10-L41","documentation":"TypeError thrown by `evaluateVolume` when the volume callback returns a value that is a number type but is NaN (after multiplying by mediaVolume). NaN typically arises from arithmetic on undefined/NaN inputs, `0/0`, or `parseInt` on a non-numeric string. The offending frame is included in the message so the developer can reproduce.","triggerScenarios":"A volume function that computes `a / b` where b can be 0, `Math.log(negative)`, arithmetic on an undefined variable, or `Number(undefined)`. For at least one frame the result is NaN.","commonSituations":"Fade curves that divide by a duration that is 0 on the first frame; looking up a value in an array with an out-of-range index producing undefined then multiplying; parsing user-supplied numeric strings that are occasionally empty.","solutions":["Guard divisions: `b === 0 ? 0 : a / b`.","Default NaN-producing inputs with `|| 0` or `?? 0`.","Wrap the callback body with `const v = compute(); return Number.isNaN(v) ? 0 : v;`."],"exampleFix":"// before\n<Video src={s} volume={(f) => f / duration} /> // duration=0 -> NaN at f=0\n\n// after\n<Video src={s} volume={(f) => (duration === 0 ? 0 : f / duration)} />","handlingStrategy":"validation","validationCode":"const safeVolume = (v: (f: number) => number, frames: number[]) => {\n  for (const f of frames) {\n    if (Number.isNaN(v(f))) throw new Error(`volume NaN at frame ${f}`);\n  }\n};","typeGuard":"const returnsNoNaN = (v: (f: number) => number, f: number): boolean =>\n  !Number.isNaN(v(f));","tryCatchPattern":null,"preventionTips":["Guard all divisions against zero denominators.","Default potentially-undefined operands with `?? 0`.","Add a final `Number.isNaN(x) ? 0 : x` clamp in volume callbacks."],"tags":["audio","volume","validation","nan"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}