Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Remove `@remotion/media-parser` dependency

JonnyBurger13fcf4be65a7
diff --git a/bun.lock b/bun.lock
index 0d1966bd75..999f4d54ca 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1201,7 +1201,6 @@
"name": "@remotion/studio",
"version": "4.0.365",
"dependencies": {
- "@remotion/media-parser": "workspace:*",
"@remotion/media-utils": "workspace:*",
"@remotion/player": "workspace:*",
"@remotion/renderer": "workspace:*",
diff --git a/packages/studio/bundle.ts b/packages/studio/bundle.ts
index 30c48de845..569e3c70ce 100644
--- a/packages/studio/bundle.ts
+++ b/packages/studio/bundle.ts
@@ -13,7 +13,6 @@ const external = [
'@remotion/renderer/client',
'@remotion/renderer/pure',
'@remotion/renderer/error-handling',
- '@remotion/media-parser/worker',
'source-map',
'zod',
'remotion/no-react',
diff --git a/packages/studio/package.json b/packages/studio/package.json
index 7af1d8d5c4..2a45cd92a6 100644
--- a/packages/studio/package.json
+++ b/packages/studio/package.json
@@ -28,7 +28,6 @@
"remotion": "workspace:*",
"@remotion/player": "workspace:*",
"@remotion/media-utils": "workspace:*",
- "@remotion/media-parser": "workspace:*",
"@remotion/renderer": "workspace:*",
"@remotion/web-renderer": "workspace:*",
"@remotion/studio-shared": "workspace:*",
diff --git a/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx b/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx
index dac11470ad..8e6c4dda0a 100644
--- a/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx
+++ b/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx
@@ -1,4 +1,3 @@
-import {WEBCODECS_TIMESCALE} from '@remotion/media-parser';
import React, {useEffect, useRef, useState} from 'react';
import {useVideoConfig} from 'remotion';
import {extractFrames} from '../../helpers/extract-frames';
@@ -27,6 +26,7 @@ const containerStyle: React.CSSProperties = {
fontFamily: 'Arial, Helvetica',
};
+const WEBCODECS_TIMESCALE = 1_000_000;
const MAX_TIME_DEVIATION = WEBCODECS_TIMESCALE * 0.05;
const getDurationOfOneFrame = ({
diff --git a/packages/studio/src/helpers/use-max-media-duration.ts b/packages/studio/src/helpers/use-max-media-duration.ts
index 9857ef2c8b..2f2b151728 100644
--- a/packages/studio/src/helpers/use-max-media-duration.ts
+++ b/packages/studio/src/helpers/use-max-media-duration.ts
@@ -1,9 +1,5 @@
-import {
- hasBeenAborted,
- mediaParserController,
- parseMedia,
-} from '@remotion/media-parser';
import {getVideoMetadata} from '@remotion/media-utils';
+import {ALL_FORMATS, Input, InputDisposedError, UrlSource} from 'mediabunny';
import {useEffect, useState} from 'react';
import {type TSequence} from 'remotion';
@@ -33,40 +29,36 @@ export const useMaxMediaDuration = (s: TSequence, fps: number) => {
return;
}
- const controller = mediaParserController();
-
- parseMedia({
- src,
- controller,
- acknowledgeRemotionLicense: true,
- onDurationInSeconds: (duration) => {
- const durationOrInfinity = duration ?? Infinity;
-
- cache.set(src, Math.floor(durationOrInfinity * fps));
- setMaxMediaDuration(Math.floor(durationOrInfinity * fps));
- },
- }).catch((e) => {
- if (hasBeenAborted(e)) {
- return;
- }
+ const input = new Input({
+ formats: ALL_FORMATS,
+ source: new UrlSource(src),
+ });
+ input
+ .computeDuration()
+ .then((duration) => {
+ cache.set(src, Math.floor(duration * fps));
+ setMaxMediaDuration(Math.floor(duration * fps));
+ })
+ .catch((e) => {
+ if (e instanceof InputDisposedError) {
+ return;
+ }
- // In case of CORS errors, fall back to getVideoMetadata
- return getVideoMetadata(src)
- .then((metadata) => {
- const durationOrInfinity = metadata.durationInSeconds ?? Infinity;
+ // In case of CORS errors, fall back to getVideoMetadata
+ return getVideoMetadata(src)
+ .then((metadata) => {
+ const durationOrInfinity = metadata.durationInSeconds ?? Infinity;
- cache.set(src, Math.floor(durationOrInfinity * fps));
- setMaxMediaDuration(Math.floor(durationOrInfinity * fps));
- })
- .catch(() => {
- // Silently handle getVideoMetadata failures to prevent unhandled rejections
- });
- });
+ cache.set(src, Math.floor(durationOrInfinity * fps));
+ setMaxMediaDuration(Math.floor(durationOrInfinity * fps));
+ })
+ .catch(() => {
+ // Silently handle getVideoMetadata failures to prevent unhandled rejections
+ });
+ });
return () => {
- try {
- controller.abort();
- } catch {}
+ input.dispose();
};
}, [src, fps]);