Skip to content

🎥 Make videos programmatically with React

refine the example

Igor Samokhovets79534bb71f5d
diff --git a/packages/example/src/NewVideo/NewVideo.tsx b/packages/example/src/NewVideo/NewVideo.tsx
index 2f7d252166..fed30f146c 100644
--- a/packages/example/src/NewVideo/NewVideo.tsx
+++ b/packages/example/src/NewVideo/NewVideo.tsx
@@ -1,34 +1,17 @@
import {experimental_Video as NewVideo} from '@remotion/media';
-import {StudioInternals} from '@remotion/studio';
-import {CalculateMetadataFunction, staticFile} from 'remotion';
-const fps = 30;
-const src = staticFile('monkey-documentary.mp4') + '#t=lol';
+interface NewVideoProps {
+ src?: string;
+}
-export const calculateMetadataFn: CalculateMetadataFunction<
- Record<string, unknown>
-> = async () => {
- const slowDurationInSeconds = 2880.0806349206346;
+export const NewVideoExample: React.FC<NewVideoProps> = ({src}) => {
+ if (!src) {
+ return <div>No video source provided</div>;
+ }
- return {
- durationInFrames: Math.round(slowDurationInSeconds * fps),
- fps,
- width: 1920,
- height: 1080,
- };
-};
-
-const Component = () => {
return (
<>
<NewVideo src={src} />
</>
);
};
-
-export const NewVideoExample = StudioInternals.createComposition({
- component: Component,
- id: 'new-video',
- calculateMetadata: calculateMetadataFn,
- fps,
-});
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 7d1aa99ad3..ee91432e66 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -114,6 +114,7 @@ if (alias !== 'alias') {
const INCLUDE_COMP_BREAKING_GET_COMPOSITIONS = false;
+import {parseMedia} from '@remotion/media-parser';
import {zMatrix} from '@remotion/zod-types';
import {ThreeDCheck} from './3DCheck';
import {ThreeDContext} from './3DContext';
@@ -668,7 +669,37 @@ export const Index: React.FC = () => {
/>
</Folder>
<Folder name="new-video-tests">
- <NewVideoExample />
+ <Composition
+ id="new-video"
+ component={NewVideoExample}
+ fps={30}
+ defaultProps={{
+ src: staticFile('demo_smpte_h264_pcm.mkv'),
+ }}
+ calculateMetadata={async ({props}) => {
+ const fps = 30;
+
+ const {slowDurationInSeconds, dimensions} = await parseMedia({
+ src: props.src as string,
+ fields: {
+ slowDurationInSeconds: true,
+ dimensions: true,
+ },
+ });
+
+ if (dimensions === null) {
+ throw new Error('Dimensions are null');
+ }
+
+ return {
+ props: props,
+ durationInFrames: Math.round(slowDurationInSeconds * fps),
+ fps,
+ width: dimensions.width,
+ height: dimensions.height,
+ };
+ }}
+ />
<Composition
id="video-testing-playback-codec"
component={VideoTestingPlayback}