Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/can-decode.md
1---2name: can-decode3description: Check if a video can be decoded by the browser using Mediabunny4metadata:5tags: decode, validation, video, audio, compatibility, browser6---78# Checking if a video can be decoded910Use Mediabunny to check if a video can be decoded by the browser before attempting to play it.1112First, install the right version of Mediabunny:1314```bash15npx remotion add mediabunny16```1718## The `canDecode()` function1920This function can be copy-pasted into any project.2122```tsx23import { Input, ALL_FORMATS, UrlSource } from "mediabunny";2425export const canDecode = async (src: string) => {26const input = new Input({27formats: ALL_FORMATS,28source: new UrlSource(src, {29getRetryDelay: () => null,30}),31});3233try {34await input.getFormat();35} catch {36return false;37}3839const videoTrack = await input.getPrimaryVideoTrack();40if (videoTrack && !(await videoTrack.canDecode())) {41return false;42}4344const audioTrack = await input.getPrimaryAudioTrack();45if (audioTrack && !(await audioTrack.canDecode())) {46return false;47}4849return true;50};51```5253## Usage5455```tsx56const src = "https://remotion.media/video.mp4";57const isDecodable = await canDecode(src);5859if (isDecodable) {60console.log("Video can be decoded");61} else {62console.log("Video cannot be decoded by this browser");63}64```6566## Using with Blob6768For file uploads or drag-and-drop, use `BlobSource`:6970```tsx71import { Input, ALL_FORMATS, BlobSource } from "mediabunny";7273export const canDecodeBlob = async (blob: Blob) => {74const input = new Input({75formats: ALL_FORMATS,76source: new BlobSource(blob),77});7879// Same validation logic as above80};81```82