remotion-dev/remotion · error · Error

Expected length is greater than stream buffer length

Error message

Expected length is greater than stream buffer length

What it means

Thrown by processAudio at process-audio.ts:74 when the ADTS header reports a frame length greater than the number of bytes currently buffered for the PID. This means the full AAC frame has not yet arrived (or will never arrive), so it cannot be sliced and processed.

Source

Thrown at packages/media-parser/src/containers/transport-stream/process-audio.ts:74

	offset: number;
	makeSamplesStartAtZero: boolean;
	avcState: AvcState;
}): Promise<void> => {
	const {streamBuffers, nextPesHeaderStore: nextPesHeader} = transportStream;
	const streamBuffer = streamBuffers.get(transportStreamEntry.pid);
	if (!streamBuffer) {
		throw new Error('Stream buffer not found');
	}

	const expectedLength =
		readAdtsHeader(streamBuffer.getBuffer())?.frameLength ?? null;

	if (expectedLength === null) {
		throw new Error('Expected length is null');
	}

	if (expectedLength > streamBuffer.getBuffer().length) {
		throw new Error('Expected length is greater than stream buffer length');
	}

	await processStreamBuffer({
		streamBuffer: makeTransportStreamPacketBuffer({
			buffers: streamBuffer.getBuffer().slice(0, expectedLength),
			offset,
			pesHeader: streamBuffer.pesHeader,
		}),
		programId: transportStreamEntry.pid,
		structure,
		sampleCallbacks,
		logLevel,
		onAudioTrack,
		onVideoTrack,
		transportStream,
		makeSamplesStartAtZero,
		avcState,
	});

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Ensure the input is fully downloaded/complete before parsing.
  2. Re-mux to drop incomplete frames: ffmpeg -i in.ts -c copy out.ts.
  3. Validate ADTS framing with faad or aacdec.
  4. If the file is a damaged capture, re-acquire the source.
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure the file is fully downloaded before parsing
import {statSync} from 'node:fs';
function isCompleteDownload(path: string, expectedSize?: number): boolean {
  return expectedSize === undefined || statSync(path).size === expectedSize;
}

Try / catch

try { await parseMedia({src}); }
catch (e) {
  if (e instanceof Error && e.message === 'Expected length is greater than stream buffer length') {
    // partial file - re-fetch or re-mux
    await runFfmpeg(['-i', src, '-c', 'copy', src + '.remux.ts']);
    await parseMedia({src: src + '.remux.ts'});
  } else throw e;
}

Prevention

When it happens

Trigger: processAudio compares expectedLength from readAdtsHeader against streamBuffer.getBuffer().length; if the header advertises a larger frame, it throws. Triggered by truncated audio packets, packet loss, partial files, or bit-flips that inflate frameLength.

Common situations: Partially downloaded .ts files; network captures with dropped packets; corrupt ADTS headers that overstate frame length; live streams where the parser is invoked before enough data has accumulated.

Related errors


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