Skip to content

🎥 Make videos programmatically with React

easier OffthreadVideoTestbed

Jonny Burger07d071ce3dff
diff --git a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx
index ec0fb62d09..981a797ada 100644
--- a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx
+++ b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx
@@ -1,15 +1,26 @@
-import {Loop, OffthreadVideo, staticFile} from 'remotion';
-
-export const OffthreadRemoteVideo: React.FC = () => {
- return (
- <Loop durationInFrames={15 * 30}>
- <OffthreadVideo src={staticFile('vid1.mp4')} />
- </Loop>
- );
+import {getVideoMetadata} from '@remotion/media-utils';
+import {CalculateMetadataFunction, OffthreadVideo} from 'remotion';
+
+type Props = {
+ src: string;
+};
+
+const fps = 30;
+
+export const calculateMetadataFn: CalculateMetadataFunction<Props> = async ({
+ props,
+}) => {
+ const {src} = props;
+ const duration = await getVideoMetadata(src);
+
+ return {
+ durationInFrames: duration.durationInSeconds * fps,
+ fps,
+ };
};
-export const OffthreadLocalVideo: React.FC<{
+export const OffthreadRemoteVideo: React.FC<{
src: string;
}> = ({src}) => {
- return <OffthreadVideo src={staticFile(src)} />;
+ return <OffthreadVideo src={src} />;
};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index aa7b09090a..90f20da0b1 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -31,10 +31,7 @@ import {HugePayload, hugePayloadSchema} from './HugePayload';
import {Layers} from './Layers';
import {ManyAudio} from './ManyAudio';
import {MissingImg} from './MissingImg';
-import {
- OffthreadLocalVideo,
- OffthreadRemoteVideo,
-} from './OffthreadRemoteVideo/OffthreadRemoteVideo';
+import {OffthreadRemoteVideo} from './OffthreadRemoteVideo/OffthreadRemoteVideo';
import {OrbScene} from './Orb';
import {PremountedExample} from './Premount';
import {PremountedRemoteVideos} from './Premount/RemoteVideos';
@@ -528,17 +525,6 @@ export const Index: React.FC = () => {
codec: 'mp4' as const,
}}
/>
- <Composition
- id="OffthreadLocalVideo"
- component={OffthreadLocalVideo}
- width={1080}
- height={1920}
- fps={30}
- durationInFrames={30 * 60}
- defaultProps={{
- src: 'variablefps.webm',
- }}
- />
<Composition
id="OffthreadRemoteVideo"
component={OffthreadRemoteVideo}
@@ -546,6 +532,9 @@ export const Index: React.FC = () => {
height={1080}
fps={30}
durationInFrames={30 * 60}
+ defaultProps={{
+ src: staticFile('vid1.mp4'),
+ }}
/>
<Composition
id="video-testing-webm"
diff --git a/packages/example/testoffthreadvideo.ts b/packages/example/testoffthreadvideo.ts
index 78cb22a082..93f31431be 100644
--- a/packages/example/testoffthreadvideo.ts
+++ b/packages/example/testoffthreadvideo.ts
@@ -10,7 +10,7 @@ const files = readdirSync('public/offthreadvideoregression').filter(
for (const file of files) {
console.log(`Rendering ${file}`);
execSync(
- `pnpm exec remotion render OffthreadLocalVideo --props='{"src": "offthreadvideoregression/${file}"}' out/regressions/${file}.mp4 --log=verbose`,
+ `pnpm exec remotion render OffthreadRemoteVideo --props='{"src": "offthreadvideoregression/${file}"}' out/regressions/${file}.mp4 --log=verbose`,
{stdio: 'inherit'},
);
}