{"record":{"id":"093889978e981ff8","repo":"remotion-dev/remotion","slug":"bitrate-mismatch-at-offset-initialoffset-bit","errorCode":null,"errorMessage":"Bitrate mismatch at offset ${initialOffset}: ${bitrateInKbit} !== ${cbrMp3Info.bitrateInKbit}","messagePattern":"Bitrate mismatch at offset (.+?): (.+?) !== (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/mp3/parse-mpeg-header.ts","lineNumber":39,"sourceCode":"\tif (iterator.bytesRemaining() < 32) {\n\t\treturn;\n\t}\n\n\t// parse header\n\tconst {\n\t\tframeLength,\n\t\tbitrateInKbit,\n\t\tlayer,\n\t\tmpegVersion,\n\t\tnumberOfChannels,\n\t\tsampleRate,\n\t\tsamplesPerFrame,\n\t} = parseMp3PacketHeader(iterator);\n\n\tconst cbrMp3Info = state.mp3.getMp3BitrateInfo();\n\tif (cbrMp3Info && cbrMp3Info.type === 'constant') {\n\t\tif (bitrateInKbit !== cbrMp3Info.bitrateInKbit) {\n\t\t\tthrow new Error(\n\t\t\t\t`Bitrate mismatch at offset ${initialOffset}: ${bitrateInKbit} !== ${cbrMp3Info.bitrateInKbit}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst offsetNow = iterator.counter.getOffset();\n\titerator.counter.decrement(offsetNow - initialOffset);\n\tconst data = iterator.getSlice(frameLength);\n\n\tif (state.callbacks.tracks.getTracks().length === 0) {\n\t\tconst info: Mp3Info = {\n\t\t\tlayer,\n\t\t\tmpegVersion,\n\t\t\tsampleRate,\n\t\t};\n\t\tconst asText = new TextDecoder().decode(data);\n\t\tif (asText.includes('VBRI')) {\n\t\t\tthrow new Error(","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/mp3/parse-mpeg-header.ts#L21-L57","documentation":"Thrown by `parseMpegHeader` when parsing a constant-bitrate (CBR) MP3 and a subsequent frame's bitrate (`bitrateInKbit`) differs from the bitrate recorded for the first frame (`cbrMp3Info.bitrateInKbit`). The library assumes CBR files are truly constant; encountering a different bitrate mid-stream signals inconsistency.","triggerScenarios":"After the first MP3 frame establishes a CBR bitrate in `state.mp3`, a later frame at `initialOffset` is parsed and `bitrateInKbit !== cbrMp3Info.bitrateInKbit`. This happens in `parse-mpeg-header.ts:37-43`.","commonSituations":"An MP3 file that was encoded as VBR but lacks a Xing/VBRI header, so the parser initially assumed CBR. Files that were concatenated from multiple MP3s with different bitrates. Corrupt frame headers with an incorrect bitrate index. Files where the bit reservoir or encoder switched bitrates without a VBR tag.","solutions":["Re-encode the MP3 with a consistent bitrate or with a proper Xing/VBR header so the parser recognizes it as VBR.","Use `ffmpeg` to normalize: `ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 192k output.mp3` for CBR or `-qscale:a` for VBR with header.","If the file is user-supplied, validate it with `ffprobe` to check for inconsistent bitrates.","Report the file at remotion.dev/report if it appears to be a standard MP3 that should parse."],"exampleFix":"# re-encode as proper CBR\nffmpeg -i input.mp3 -codec:a libmp3lame -b:a 192k -map_metadata 0 output.mp3","handlingStrategy":"try-catch","validationCode":"// Pre-check bitrate consistency with ffprobe\n// ffprobe -show_frames -select_streams a input.mp3 | grep pkt_size\n// If frame sizes vary significantly without a Xing header, re-encode.","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src, fields: {durationInSeconds: true}});\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Bitrate mismatch')) {\n    console.error('The MP3 has inconsistent bitrates. Re-encode as CBR or add a Xing header.');\n  }\n  throw e;\n}","preventionTips":["Re-encode MP3 files with consistent bitrate: ffmpeg -i input -b:a 192k output.mp3.","For VBR files, ensure a Xing header is present so the parser detects VBR mode.","Avoid concatenating MP3 files with different bitrates.","Validate with ffprobe that the bitrate is consistent or the file has a VBR header."],"tags":["mp3","cbr","bitrate","corrupt-file","inconsistent-encoding"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}