{"record":{"id":"1085239d1b538e20","repo":"remotion-dev/remotion","slug":"cannot-get-duration-of-vbr-mp3-file-no-sample-ra","errorCode":null,"errorMessage":"Cannot get duration of VBR MP3 file - no sample rate","messagePattern":"Cannot get duration of VBR MP3 file - no sample rate","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/mp3/get-duration.ts","lineNumber":20,"sourceCode":"import {getMpegFrameLength} from './get-frame-length';\nimport type {XingData} from './parse-xing';\nimport {getSamplesPerMpegFrame} from './samples-per-mpeg-file';\n\nexport const getDurationFromMp3Xing = ({\n\txingData,\n\tsamplesPerFrame,\n}: {\n\txingData: XingData;\n\tsamplesPerFrame: number;\n}) => {\n\tconst xingFrames = xingData.numberOfFrames;\n\tif (!xingFrames) {\n\t\tthrow new Error('Cannot get duration of VBR MP3 file - no frames');\n\t}\n\n\tconst {sampleRate} = xingData;\n\tif (!sampleRate) {\n\t\tthrow new Error('Cannot get duration of VBR MP3 file - no sample rate');\n\t}\n\n\tconst xingSamples = xingFrames * samplesPerFrame;\n\treturn xingSamples / sampleRate;\n};\n\nexport const getDurationFromMp3 = (state: ParserState): number | null => {\n\tconst mp3Info = state.mp3.getMp3Info();\n\tconst mp3BitrateInfo = state.mp3.getMp3BitrateInfo();\n\tif (!mp3Info || !mp3BitrateInfo) {\n\t\treturn null;\n\t}\n\n\tconst samplesPerFrame = getSamplesPerMpegFrame({\n\t\tlayer: mp3Info.layer,\n\t\tmpegVersion: mp3Info.mpegVersion,\n\t});\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/mp3/get-duration.ts#L2-L38","documentation":"Thrown by `getDurationFromMp3Xing` when computing a VBR MP3 duration and `xingData.sampleRate` is missing or falsy. The sample rate is required to convert sample counts into seconds; a Xing header without it is malformed.","triggerScenarios":"An MP3 file whose Xing header was parsed but the `sampleRate` field came back as `0`, `null`, or `undefined`. This happens when `parseXing` could not extract or infer the sample rate from the header data.","commonSituations":"Corrupt or non-standard Xing headers where the sample rate bytes are absent or zero. MP3 files with damaged headers from partial downloads or faulty encoders. Files where the Xing header references a frame whose sample rate couldn't be decoded.","solutions":["Re-encode the MP3 file with a well-formed encoder that writes the sample rate into the Xing header.","Convert the file to CBR MP3 or a different container (e.g., M4A/MP4) to bypass the VBR Xing path.","Validate the file with `ffprobe` or a similar tool to check header integrity.","Use try-catch around `parseMedia` and handle the corrupt file gracefully."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src, fields: {durationInSeconds: true}});\n} catch (e) {\n  if (e instanceof Error && e.message.includes('no sample rate')) {\n    console.error('The VBR MP3 has a corrupt Xing header with no sample rate.');\n  }\n  throw e;\n}","preventionTips":["Re-encode VBR MP3 files with a well-formed encoder to fix Xing header issues.","Validate audio files with ffprobe before parsing.","Prefer CBR MP3 or container formats (M4A, WebM) for more reliable parsing.","Keep try-catch around parseMedia for user-supplied files."],"tags":["mp3","vbr","xing-header","corrupt-file","sample-rate","duration"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}