Skip to content

🎥 Make videos programmatically with React

update test compositions to use new way to get metadatsa

JonnyBurgerd9613405a6b7
diff --git a/bun.lock b/bun.lock
index 0da9362273..5696ef4356 100644
--- a/bun.lock
+++ b/bun.lock
@@ -574,6 +574,7 @@
"dotenv": "9.0.2",
"hls.js": "^0.14.17",
"lottie-web": "5.13.0",
+ "mediabunny": "1.23.0",
"opentype.js": "^1.3.4",
"polished": "^4.0.5",
"prettier": "3.6.0",
diff --git a/packages/example/package.json b/packages/example/package.json
index dccda4b0a6..67cdf6ccd1 100644
--- a/packages/example/package.json
+++ b/packages/example/package.json
@@ -79,6 +79,7 @@
"babel-loader": "^8.2.2",
"dotenv": "9.0.2",
"hls.js": "^0.14.17",
+ "mediabunny": "1.23.0",
"lottie-web": "5.13.0",
"opentype.js": "^1.3.4",
"polished": "^4.0.5",
diff --git a/packages/example/src/OffthreadRemoteVideo/NewRemoteVideo.tsx b/packages/example/src/OffthreadRemoteVideo/NewRemoteVideo.tsx
index 753716e449..002ceda6cc 100644
--- a/packages/example/src/OffthreadRemoteVideo/NewRemoteVideo.tsx
+++ b/packages/example/src/OffthreadRemoteVideo/NewRemoteVideo.tsx
@@ -1,7 +1,7 @@
import {Video} from '@remotion/media';
-import {parseMedia} from '@remotion/media-parser';
import {StudioInternals} from '@remotion/studio';
import {CalculateMetadataFunction} from 'remotion';
+import {getMediaMetadata} from '../get-media-metadata';
const fps = 30;
const src = 'https://remotion.media/video.mp4' + '#t=lol';
@@ -9,17 +9,10 @@ const src = 'https://remotion.media/video.mp4' + '#t=lol';
export const calculateMetadataFn: CalculateMetadataFunction<
Record<string, unknown>
> = async () => {
- const {slowDurationInSeconds, dimensions} = await parseMedia({
- src,
- acknowledgeRemotionLicense: true,
- fields: {
- slowDurationInSeconds: true,
- dimensions: true,
- },
- });
+ const {durationInSeconds, dimensions} = await getMediaMetadata(src);
return {
- durationInFrames: Math.round(slowDurationInSeconds * fps),
+ durationInFrames: Math.round(durationInSeconds * fps),
fps,
width: dimensions?.width ?? 100,
height: dimensions?.height ?? 100,
diff --git a/packages/example/src/get-media-metadata.ts b/packages/example/src/get-media-metadata.ts
new file mode 100644
index 0000000000..af72ee3da4
--- /dev/null
+++ b/packages/example/src/get-media-metadata.ts
@@ -0,0 +1,27 @@
+import {ALL_FORMATS, Input, UrlSource} from 'mediabunny';
+
+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: videoTrack.displayWidth,
+ height: videoTrack.displayHeight,
+ }
+ : null;
+ const packetStats = await videoTrack?.computePacketStats(50);
+ const fps = packetStats?.averagePacketRate ?? null;
+
+ return {
+ durationInSeconds,
+ dimensions,
+ fps,
+ };
+};