Capítulo 735 de 988

Chapter 735: Check if a video can be decoded using Mediabunny

Core Idea

Before attempting to load a video into <Video>, you may want to check if the video can be decoded by the browser. This can be done using Mediabunny.

Key Concepts

  • Usage
  • Check if a video can be decoded
  • See also

Code Examples

export const canDecode = async (src: string | Blob) => {
  const input = new Input({
    formats: ALL_FORMATS,
    source: typeof src === 'string' ? new UrlSource(src) : new BlobSource(src),
  });

  try {
    await input.getFormat();
  } catch {
    return false;
  }

  const videoTrack = await input.getPrimaryVideoTrack();
  if (videoTrack && !(await videoTrack.canDecode())) {
    return false;
  }

  const audioTrack = await input.getPrimaryAudioTrack();
  if (audioTrack && !(await audioTrack.canDecode())) {
    return false;
  }

  return true;
};
  • What it demonstrates: Usage pattern for Check if a video can be decoded using Mediabunny from the official docs.

Key Takeaways

  1. Understand usage when working with Check if a video can be decoded using Mediabunny.
  2. Understand check if a video can be decoded when working with Check if a video can be decoded using Mediabunny.
  3. Understand see also when working with Check if a video can be decoded using Mediabunny.

Connects To

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