Capítulo 740 de 988

Chapter 740: Getting metadata from a video in JavaScript

Core Idea

If you would like to obtain metadata from a video or audio in JavaScript, such as:

Key Concepts

  • Getting metadata from a URL
  • Why we recommend Mediabunny
  • When not to use Mediabunny
  • See also

Code Examples

export const getMediaMetadata = async (src: string) => {
  const input = new Input({
    formats: ALL_FORMATS,
    source: new UrlSource(src, {
      getRetryDelay: () => null,
    }),
  });

  const durationInSeconds = await input.computeDuration();
  const videoTrack = await input.getPrimaryVideoTrack();
  const dimensions = videoTrack
    ? {
        width: await videoTrack.getDisplayWidth(),
        height: await videoTrack.getDisplayHeight(),
      }
    : null;
  const frameRateMetrics = videoTrack
    ? await videoTrack.computeFrameRateMetrics()
    : null;
  const fps =
    frameRateMetrics === null || frameRateMetrics.probedPacketCount < 2
      ? null
      : frameRateMetrics.bestGuessFrameRate;

  return {
    durationInSeconds,
    dimensions,
    fps,
  };
};
  • What it demonstrates: Usage pattern for Getting metadata from a video in JavaScript from the official docs.

Key Takeaways

  1. Understand getting metadata from a url when working with Getting metadata from a video in JavaScript.
  2. Understand why we recommend mediabunny when working with Getting metadata from a video in JavaScript.
  3. Understand when not to use mediabunny when working with Getting metadata from a video in JavaScript.
  4. Understand see also when working with Getting metadata from a video in JavaScript.

Connects To

  • can Decode: related page in the Mediabunny (@remotion/mediabunny) section.
  • Extract Frames: related page in the Mediabunny (@remotion/mediabunny) section.
  • Extract Thumbnail: related page in the Mediabunny (@remotion/mediabunny) section.