Skip to content

🎥 Make videos programmatically with React

Docs: Check if a video can be decoded using Mediabunny

JonnyBurger3b726fee3967
diff --git a/packages/docs/docs/mediabunny/can-decode.mdx b/packages/docs/docs/mediabunny/can-decode.mdx
new file mode 100644
index 0000000000..3df6c083ac
--- /dev/null
+++ b/packages/docs/docs/mediabunny/can-decode.mdx
@@ -0,0 +1,58 @@
+---
+image: /generated/articles-docs-mediabunny-can-decode.png
+title: Check if a video can be decoded using Mediabunny
+crumb: 'Mediabunny'
+sidebar_label: Check if video can be decoded
+---
+
+Before attempting to load a video into [`<Video>`](/docs/media/video), you may want to check if the video can be decoded by the browser. This can be done using [Mediabunny](https://mediabunny.dev).
+
+Here's a `canDecode()` function you can copy and paste into your project:
+
+```ts twoslash title="can-decode.ts"
+import {ALL_FORMATS, Input, UrlSource} from 'mediabunny';
+
+export const canDecode = async (src: string) => {
+ const input = new Input({
+ formats: ALL_FORMATS,
+ source: new UrlSource(src),
+ });
+ const videoTrack = await input.getPrimaryVideoTrack();
+ if (videoTrack) {
+ if (!(await videoTrack.canDecode())) {
+ return false;
+ }
+ }
+
+ const audioTrack = await input.getPrimaryAudioTrack();
+
+ if (audioTrack) {
+ if (!(await audioTrack.canDecode())) {
+ return false;
+ }
+ }
+
+ return true;
+};
+```
+
+## Usage
+
+### Check if a video can be decoded
+
+```ts
+const src = 'https://remotion.media/video.mp4';
+const isDecodable = await canDecode(src);
+
+if (isDecodable) {
+ console.log('Video can be decoded');
+} else {
+ console.log('Video cannot be decoded');
+}
+```
+
+## See also
+
+- [Mediabunny Documentation](https://mediabunny.dev)
+- [Extracting video frames](/docs/mediabunny/extract-frames)
+- [Supported formats](/docs/mediabunny/formats)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 0c3622ce09..f83561bbb2 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1229,6 +1229,7 @@ const sidebars: SidebarsConfig = {
'mediabunny/new-video',
'mediabunny/metadata',
'mediabunny/extract-frames',
+ 'mediabunny/can-decode',
'mediabunny/formats',
'mediabunny/version',
],
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 74e139e205..2b70799142 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -503,6 +503,15 @@ export const articles = [
noAi: false,
slug: 'chromium-flags',
},
+ {
+ id: 'cli/add',
+ title: 'npx remotion add',
+ relativePath: 'docs/cli/add.mdx',
+ compId: 'articles-docs-cli-add',
+ crumb: 'CLI Reference',
+ noAi: false,
+ slug: 'cli/add',
+ },
{
id: 'cli/benchmark',
title: 'npx remotion benchmark',
@@ -3338,6 +3347,15 @@ export const articles = [
noAi: false,
slug: 'media/video',
},
+ {
+ id: 'mediabunny/can-decode',
+ title: 'Check if a video can be decoded using Mediabunny',
+ relativePath: 'docs/mediabunny/can-decode.mdx',
+ compId: 'articles-docs-mediabunny-can-decode',
+ crumb: 'Mediabunny',
+ noAi: false,
+ slug: 'mediabunny/can-decode',
+ },
{
id: 'mediabunny/extract-frames',
title: 'Extracting frames from a video in JavaScript',
diff --git a/packages/docs/static/generated/articles-docs-cli-add.png b/packages/docs/static/generated/articles-docs-cli-add.png
new file mode 100644
index 0000000000..37a13c93f2
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-cli-add.png differ
diff --git a/packages/docs/static/generated/articles-docs-mediabunny-can-decode.png b/packages/docs/static/generated/articles-docs-mediabunny-can-decode.png
new file mode 100644
index 0000000000..83eae34d68
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-mediabunny-can-decode.png differ