🎥 Make videos programmatically with React
simplification
Jonny Burger4601a769be0d
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsxindex 1852366f45..87b40638e8 100644--- a/packages/core/src/video/VideoForRendering.tsx+++ b/packages/core/src/video/VideoForRendering.tsx@@ -1,11 +1,11 @@-import React, {useEffect, useMemo, useRef} from 'react';+import React, {useEffect, useRef} from 'react';import {continueRender, delayRender} from '../ready-manager';import {useCurrentFrame} from '../use-frame';import {useUnsafeVideoConfig} from '../use-unsafe-video-config';import {RemotionVideoProps} from './props';export const VideoForRendering: React.FC<RemotionVideoProps> = (props) => {- const currentFrame = useCurrentFrame();+ const frame = useCurrentFrame();const videoConfig = useUnsafeVideoConfig();const videoRef = useRef<HTMLVideoElement>(null);@@ -13,16 +13,11 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = (props) => {throw new Error('No video config found');}- const frameInSeconds = useMemo(() => currentFrame / videoConfig.fps, [- currentFrame,- videoConfig.fps,- ]);-useEffect(() => {if (!videoRef.current) {return;}- console.log('delaying');+ const frameInSeconds = frame / videoConfig.fps;const handle = delayRender();if (videoRef.current.currentTime === frameInSeconds) {videoRef.current.addEventListener(@@ -32,17 +27,17 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = (props) => {},{once: true});- } else {- videoRef.current.currentTime = frameInSeconds;- videoRef.current.addEventListener(- 'seeked',- () => {- continueRender(handle);- },- {once: true}- );+ return;}- }, [currentFrame, frameInSeconds, videoConfig.fps]);+ videoRef.current.currentTime = frameInSeconds;+ videoRef.current.addEventListener(+ 'seeked',+ () => {+ continueRender(handle);+ },+ {once: true}+ );+ }, [frame, videoConfig.fps]);return <video ref={videoRef} {...props} />;};