Capítulo 679 de 988

Chapter 679: Fast and slow operations

Core Idea

:::warning We are phasing out Media Parser and are moving to Mediabunny!

Key Concepts

  • Full parsing operations
  • Metadata-only operations
  • Header-only operations
  • Seeking required
  • Example
  • See also

Code Examples

// Some fields only require the first few bytes of the file to be read:
const result = await parseMedia({
  src: 'https://remotion.media/video.mp4',
  fields: {
    size: true,
    container: true,
    internalStats: true,
  },
});

console.log(result.internalStats.finalCursorOffset); // 12

// Reading the metadata of the video will only require the metadata section to be parsed.
// You can also use onVideoTrack() and return null to retrieve track information but to not get the samples.
const result2 = await parseMedia({
  src: 'https://remotion.media/video.mp4',
  fields: {
    durationInSeconds: true,
    dimensions: true,
    internalStats: true,
  },
  onVideoTrack: ({track}) => {
    console.log(track);
    return null;
  },
});

console.log(result2.internalStats.finalCursorOffset); // 4000
console.log(result2.dimensions);

// Asking for all video samples requires parsing the whole file
const result3 = await parseMedia({
  src: 'https://remotion.media/video.mp4',
  fields: {
    internalStats: true,
  },
  onVideoTrack: () => {
    return (videoSample) => console.log(videoSample);
  },
});

console.log(result3.internalStats.finalCursorOffset); // 1870234802
  • What it demonstrates: Usage pattern for Fast and slow operations from the official docs.

Key Takeaways

  1. Understand full parsing operations when working with Fast and slow operations.
  2. Understand metadata-only operations when working with Fast and slow operations.
  3. Understand header-only operations when working with Fast and slow operations.
  4. Understand seeking required when working with Fast and slow operations.
  5. Understand example when working with Fast and slow operations.

Connects To

  • Download and Parse: related page in the Media Parser (@remotion/media-parser) section.
  • Download and Parse Media: related page in the Media Parser (@remotion/media-parser) section.
  • Fields: related page in the Media Parser (@remotion/media-parser) section.