remotion-dev/remotion · error

Invalid sync code

Error message

Invalid sync code

What it means

Thrown by parseFlacFrame() when parsing the first FLAC frame (blockingBit strategy undefined) and the initial 15 bits do not equal the FLAC sync code 0b111111111111100 (0xFFF8 shifted). Per RFC 9639, every FLAC frame must begin with this 14-bit sync code (0b11111111111110) followed by a reserved bit. If the bits don't match, the data at the current position is not a valid FLAC frame header.

Source

Thrown at packages/media-parser/src/containers/flac/parse-flac-frame.ts:165

	iterator.destroy();
};

export const parseFlacFrame = async ({
	state,
	iterator,
}: {
	state: ParserState;
	iterator: BufferIterator;
}): Promise<ParseResult> => {
	const blockingBit = state.flac.getBlockingBitStrategy();
	const offset = iterator.counter.getOffset();
	const {returnToCheckpoint} = iterator.startCheckpoint();
	iterator.startReadingBits();

	if (blockingBit === undefined) {
		const bits = iterator.getBits(15);
		if (bits !== 0b111111111111100) {
			throw new Error('Invalid sync code');
		}

		state.flac.setBlockingBitStrategy(iterator.getBits(1));
	} else if (blockingBit === 1) {
		const bits = iterator.getBits(16);
		if (bits !== 0b1111111111111001) {
			throw new Error('Blocking bit changed, it should not');
		}
	} else if (blockingBit === 0) {
		const bits = iterator.getBits(16);
		if (bits !== 0b1111111111111000) {
			throw new Error('Blocking bit changed, it should not');
		}
	}

	const setBlockingBit = state.flac.getBlockingBitStrategy();
	if (setBlockingBit === undefined) {
		throw new Error('Blocking bit should be set');

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Verify the file is valid FLAC: `ffprobe input.flac` or `flac -t input.flac`.
  2. Re-encode from a known-good source: `ffmpeg -i input.flac output.flac`.
  3. Switch to Mediabunny (https://www.remotion.dev/docs/mediabunny/metadata).
  4. Report the file to the Remotion team if it plays correctly in standard players.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const result = await parseMedia({src, fields: {durationInSeconds: true}});
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid sync code') {
    console.error('FLAC frame sync code mismatch. File may be corrupt. Verify: flac -t <file>');
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: The parser's read position lands on bytes whose first 15 bits are not the FLAC sync pattern. This happens with corrupt frame data, a misaligned read position (e.g. after skipping padding or encountering non-frame data), or a file that is not actually FLAC but was detected as such.

Common situations: Corrupt FLAC files with damaged frame headers. Files with trailing garbage or embedded metadata after the audio data. False-positive FLAC detection where a non-FLAC file has an 'fLaC' marker but incompatible content. Seeking to an offset that is not frame-aligned.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/c635890a07a49e42. Report an issue: GitHub.