Back to Remotion

bufferWriter

packages/docs/docs/webcodecs/buffer-writer.mdx

4.0.4571.9 KB
Original Source

:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny! :::

import {LicenseDisclaimer} from './LicenseDisclaimer'; import {UnstableDisclaimer} from './UnstableDisclaimer';

<details> <summary>💼 Important License Disclaimer</summary> <LicenseDisclaimer /> </details>

:::warning Unstable API: The writer interface is experimental. The API may change in the future. :::

A writer for @remotion/webcodecs that writes to an in-memory resizable ArrayBuffer.

Can be used for convertMedia() to write the converted output to memory as a buffer.

Example

tsx
import {convertMedia} from '@remotion/webcodecs';
import {bufferWriter} from '@remotion/webcodecs/buffer';

const result = await convertMedia({
  src: 'https://remotion.media/BigBuckBunny.mp4',
  container: 'webm',
  writer: bufferWriter,
});

const blob = await result.save();

Memory limitations

The bufferWriter uses a resizable ArrayBuffer with a maximum size of 2GB. If your output file would exceed this limit, the conversion will fail.

tsx
import {convertMedia} from '@remotion/webcodecs';
import {bufferWriter} from '@remotion/webcodecs/buffer';

try {
  const result = await convertMedia({
    src: 'very-large-video.mp4',
    container: 'webm',
    writer: bufferWriter,
  });
} catch (error) {
  if ((error as Error).message.includes('Could not create buffer writer')) {
    // Handle case where ArrayBuffer cannot be resized further
    console.log('File too large for buffer writer, consider using webFsWriter');
  }
}

See also