🎥 Make videos programmatically with React
add tests
Jonny Burger68a59afd3fe5
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex 4ae90df43a..998b274e75 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -177,6 +177,19 @@ export const Index: React.FC = () => {fps={30}durationInFrames={100}defaultProps={{+ offthread: false,+ codec: 'mp4' as const,+ }}+ />+ <Composition+ id="video-testing-mp4-offthread"+ component={VideoTesting}+ width={1080}+ height={1080}+ fps={30}+ durationInFrames={100}+ defaultProps={{+ offthread: true,codec: 'mp4' as const,}}/>@@ -196,6 +209,19 @@ export const Index: React.FC = () => {fps={30}durationInFrames={100}defaultProps={{+ offthread: false,+ codec: 'webm' as const,+ }}+ />+ <Composition+ id="video-testing-webm-offthread"+ component={VideoTesting}+ width={1080}+ height={1080}+ fps={30}+ durationInFrames={100}+ defaultProps={{+ offthread: true,codec: 'webm' as const,}}/>diff --git a/packages/example/src/VideoTesting/index.tsx b/packages/example/src/VideoTesting/index.tsxindex 3b982b9b19..ff978dacbb 100644--- a/packages/example/src/VideoTesting/index.tsx+++ b/packages/example/src/VideoTesting/index.tsx@@ -1,15 +1,25 @@-import {OffthreadVideo, Sequence, staticFile, useVideoConfig} from 'remotion';+import {+ OffthreadVideo,+ Sequence,+ staticFile,+ useVideoConfig,+ Video,+} from 'remotion';export const VideoTesting: React.FC<{codec: 'mp4' | 'webm';-}> = ({codec}) => {+ offthread: boolean;+}> = ({codec, offthread}) => {const {durationInFrames} = useVideoConfig();const videoMp4 = staticFile('./framer.mp4');const videoWebm = staticFile('./framer.webm');++ const Comp = offthread ? OffthreadVideo : Video;+return (<div><Sequence from={0} durationInFrames={durationInFrames}>- <OffthreadVideo src={codec === 'mp4' ? videoMp4 : videoWebm} />+ <Comp src={codec === 'mp4' ? videoMp4 : videoWebm} /></Sequence></div>);diff --git a/packages/it-tests/src/rendering/frame-accuracy.test.ts b/packages/it-tests/src/rendering/frame-accuracy.test.tsindex 5a18497ed4..239e4afea7 100644--- a/packages/it-tests/src/rendering/frame-accuracy.test.ts+++ b/packages/it-tests/src/rendering/frame-accuracy.test.ts@@ -9,7 +9,10 @@ function selectColor(color: string, frame: number) {return Math.floor((random(`${color}-${frame}`) * 255) % 255);}-const getMissedFramesforCodec = async (codec: "mp4" | "webm") => {+const getMissedFramesforCodec = async (+ codec: "mp4" | "webm",+ offthread: boolean+) => {const outputPath = await fs.promises.mkdtemp(path.join(os.tmpdir(), "remotion-"));@@ -22,7 +25,7 @@ const getMissedFramesforCodec = async (codec: "mp4" | "webm") => {"remotion","render","src/index.tsx",- `video-testing-${codec}`,+ `video-testing-${codec}${offthread ? "-offthread" : ""}`,outputPath,"--image-format","jpeg",@@ -80,12 +83,21 @@ const getMissedFramesforCodec = async (codec: "mp4" | "webm") => {return missedFrames;};-test("should render correct frames from embedded videos - WebM", async () => {- const missedFrames = await getMissedFramesforCodec("webm");+test("should render correct frames from embedded videos - WebM onthread", async () => {+ const missedFrames = await getMissedFramesforCodec("webm", false);+ expect(missedFrames).toBe(0);+});+test("should render correct frames from embedded videos - WebM offthread", async () => {+ const missedFrames = await getMissedFramesforCodec("webm", true);+ expect(missedFrames).toBe(0);+});++test("should render correct frames from embedded videos - MP4 onthread", async () => {+ const missedFrames = await getMissedFramesforCodec("mp4", false);expect(missedFrames).toBe(0);});-test("should render correct frames from embedded videos - MP4", async () => {- const missedFrames = await getMissedFramesforCodec("mp4");+test("should render correct frames from embedded videos - MP4 offthread", async () => {+ const missedFrames = await getMissedFramesforCodec("mp4", true);expect(missedFrames).toBe(0);});