{"record":{"id":"a3b98a9f63d838a4","repo":"remotion-dev/remotion","slug":"reserved-sampling-frequency","errorCode":null,"errorMessage":"Reserved sampling frequency","messagePattern":"Reserved sampling frequency","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/mp3/parse-packet-header.ts","lineNumber":27,"sourceCode":"\nfunction getSamplingFrequency({\n\tbits,\n\tmpegVersion,\n}: {\n\tbits: number;\n\tmpegVersion: MpegVersion;\n}): number {\n\tconst samplingTable: Record<number, Record<string, number | 'reserved'>> = {\n\t\t0b00: {MPEG1: 44100, MPEG2: 22050},\n\t\t0b01: {MPEG1: 48000, MPEG2: 24000},\n\t\t0b10: {MPEG1: 32000, MPEG2: 16000},\n\t\t0b11: {MPEG1: 'reserved', MPEG2: 'reserved'},\n\t};\n\n\tconst key = `MPEG${mpegVersion}`;\n\tconst value = samplingTable[bits][key];\n\tif (value === 'reserved') {\n\t\tthrow new Error('Reserved sampling frequency');\n\t}\n\n\tif (!value) {\n\t\tthrow new Error(\n\t\t\t'Invalid sampling frequency for MPEG version: ' +\n\t\t\t\tJSON.stringify({bits, version: mpegVersion}),\n\t\t);\n\t}\n\n\treturn value;\n}\n\nfunction getBitrateKB({\n\tbits,\n\tmpegVersion,\n\tlevel,\n}: {\n\tbits: number;","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/mp3/parse-packet-header.ts#L9-L45","documentation":"Thrown by `getSamplingFrequency` when the 2-bit sampling frequency index read from the MPEG frame header is `0b11`, which the MPEG specification marks as 'reserved' (invalid). The sampling frequency table in `parse-packet-header.ts:17-22` maps `0b11` to `'reserved'` for both MPEG1 and MPEG2.","triggerScenarios":"While parsing an MPEG audio frame header in `innerParseMp3PacketHeader`, the 2-bit `samplingFrequencyIndex` (read at line 227) is `0b11`, triggering the reserved-value check at line 26-28.","commonSituations":"Corrupt MP3 frame headers where the sampling frequency bits are damaged. Files that are not actually MPEG audio but were misidentified. Random data being interpreted as an MPEG frame. Partially-downloaded or truncated files.","solutions":["Verify the file is a valid MP3 using `ffprobe -i file.mp3`.","Re-download or re-encode the file if corruption is suspected.","If the file is not MP3, use the correct parser or convert it.","Use try-catch around `parseMedia` to handle corrupt files gracefully."],"exampleFix":"# validate the MP3 file\nffprobe -i input.mp3 2>&1 | grep -i 'stream'\n\n# re-encode if corrupt\nffmpeg -i input.mp3 -codec:a libmp3lame output.mp3","handlingStrategy":"try-catch","validationCode":"// Validate MP3 frame header integrity\nasync function hasValidFrameHeaders(file: File): Promise<boolean> {\n  try {\n    const buf = await file.slice(0, 4).arrayBuffer();\n    const bytes = new Uint8Array(buf);\n    // Skip ID3 if present; otherwise check sync word\n    if (bytes[0] !== 0xff) {\n      // might have ID3 - that's fine, deeper validation needed\n      return true;\n    }\n    return true; // deeper validation requires parsing bit fields\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src, fields: {durationInSeconds: true}});\n} catch (e) {\n  if (e instanceof Error && e.message === 'Reserved sampling frequency') {\n    console.error('The MP3 frame header contains a reserved (invalid) sampling frequency.');\n  }\n  throw e;\n}","preventionTips":["Validate MP3 files with ffprobe -v error before parsing.","Re-encode files from a known-good source if frame headers are corrupt.","Check for partial downloads or storage corruption.","Use try-catch around parseMedia for untrusted audio files."],"tags":["mp3","corrupt-file","invalid-header","sampling-frequency","mpeg-spec"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}