🎥 Make videos programmatically with React
added `<Freeze />` component
Shankhadeep Dey050822bbe799
diff --git a/packages/core/src/freeze.tsx b/packages/core/src/freeze.tsxindex fb642cf5c3..e0edbf1695 100644--- a/packages/core/src/freeze.tsx+++ b/packages/core/src/freeze.tsx@@ -1,16 +1,22 @@import React, {useContext, useMemo} from 'react';-import {TimelineContext,TimelineContextValue} from './timeline-position-state';-+import {TimelineContext, TimelineContextValue} from './timeline-position-state';type FreezeProps = {frame: number;};-const Freeze: React.FC<FreezeProps> = ({frame,children}) => {+const Freeze: React.FC<FreezeProps> = ({frame, children}) => {+ if (typeof frame !== 'number') {+ throw new Error(+ `You passed to 'frame' an argument of type ${typeof frame}, but it must be a number.`+ );+ }+const context = useContext(TimelineContext);const value: TimelineContextValue = useMemo(() => {return {...context,+ playing: false,frame,};}, [context, frame]);@@ -22,4 +28,4 @@ const Freeze: React.FC<FreezeProps> = ({frame,children}) => {);};-export {Freeze}\ No newline at end of file+export {Freeze};diff --git a/packages/core/src/test/freeze.test.tsx b/packages/core/src/test/freeze.test.tsxnew file mode 100644index 0000000000..030a481b61--- /dev/null+++ b/packages/core/src/test/freeze.test.tsx@@ -0,0 +1,20 @@+import {render} from '@testing-library/react';+import {Freeze} from '../freeze';+import {expectToThrow} from './expect-to-throw';++describe('Throw with invalid duration props', () => {+ test('It should throw if Freeze has string as frame prop value', () => {+ expectToThrow(+ // @ts-expect-error+ () => render(<Freeze frame={'0'} />),+ /You passed to 'frame' an argument of type string, but it must be a number./+ );+ });+ test('It should throw if Freeze has undefined as frame prop value', () => {+ expectToThrow(+ // @ts-expect-error+ () => render(<Freeze />),+ /You passed to 'frame' an argument of type undefined, but it must be a number./+ );+ });+});diff --git a/packages/example/src/VideoTesting/index.tsx b/packages/example/src/VideoTesting/index.tsxindex 8497c8a904..1e36f968b8 100644--- a/packages/example/src/VideoTesting/index.tsx+++ b/packages/example/src/VideoTesting/index.tsx@@ -1,4 +1,4 @@-import {Sequence, useVideoConfig, Video} from 'remotion';+import {Sequence, useVideoConfig, Video,Freeze} from 'remotion';import videoMp4 from './framer.mp4';import videoWebm from './framer.webm';@@ -8,9 +8,14 @@ export const VideoTesting: React.FC<{const {durationInFrames} = useVideoConfig();return (<div>- <Sequence from={0} durationInFrames={durationInFrames}>+ <Sequence from={0} durationInFrames={50}><Video src={codec === 'mp4' ? videoMp4 : videoWebm} /></Sequence>+ <Sequence from={50} durationInFrames={durationInFrames}>+ <Freeze frame={50}>+ <Video startFrom={50} src={codec === 'mp4' ? videoMp4 : videoWebm} />+ </Freeze>+ </Sequence></div>);};