🎥 Make videos programmatically with React
fixes
Jonny Burger673a3dcb6070
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsxindex a4940a3c71..049b947f9f 100644--- a/packages/core/src/video/VideoForDevelopment.tsx+++ b/packages/core/src/video/VideoForDevelopment.tsx@@ -1,4 +1,4 @@-import React, {useEffect, useRef} from 'react';+import React, {useEffect, useRef, useState} from 'react';import {usePlayingState} from '../timeline-position-state';import {useAbsoluteCurrentFrame, useCurrentFrame} from '../use-frame';import {useUnsafeVideoConfig} from '../use-unsafe-video-config';@@ -11,6 +11,8 @@ export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {const videoConfig = useUnsafeVideoConfig();const [playing] = usePlayingState();+ const [videoDuration, setVideoDuration] = useState(0);+useEffect(() => {if (playing) {videoRef.current?.play();@@ -27,15 +29,14 @@ export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {if (!videoConfig) {throw new Error('No video config found');}- const currentTime = currentFrame / videoConfig.fps;- console.log(currentFrame, currentTime);+ const currentTime = (currentFrame + 1) / videoConfig.fps;if (!playing || absoluteFrame === 0) {videoRef.current.currentTime = currentTime;return;}- if (videoRef.current.paused) {+ if (videoRef.current.paused && !videoRef.current.ended) {videoRef.current.currentTime = currentTime;videoRef.current.play();}diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex a1988f498c..262d96fe1d 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -1,9 +1,9 @@import React from 'react';import {Composition} from 'remotion';-import {AudioTesting} from './AudioTesting';import {Framer} from './Framer';import {MissingImg} from './MissingImg';import {TenFrameTester} from './TenFrameTester';+import {VideoTesting} from './VideoTesting';export const Index: React.FC = () => {return (@@ -149,12 +149,12 @@ export const Index: React.FC = () => {durationInFrames={10}/><Composition- id="audio-testing"- component={AudioTesting}+ id="video-testing"+ component={VideoTesting}width={1080}height={1080}fps={30}- durationInFrames={1}+ durationInFrames={100}/><Compositionid="framer"diff --git a/packages/example/src/AudioTesting/framer.mp4 b/packages/example/src/VideoTesting/framer.mp4similarity index 100%rename from packages/example/src/AudioTesting/framer.mp4rename to packages/example/src/VideoTesting/framer.mp4diff --git a/packages/example/src/AudioTesting/index.tsx b/packages/example/src/VideoTesting/index.tsxsimilarity index 65%rename from packages/example/src/AudioTesting/index.tsxrename to packages/example/src/VideoTesting/index.tsxindex bd809db788..b8817c2734 100644--- a/packages/example/src/AudioTesting/index.tsx+++ b/packages/example/src/VideoTesting/index.tsx@@ -1,11 +1,11 @@import {Sequence, useVideoConfig, Video} from 'remotion';import video from './framer.mp4';-export const AudioTesting: React.FC = () => {+export const VideoTesting: React.FC = () => {const {durationInFrames} = useVideoConfig();return (<div>- <Sequence from={0} durationInFrames={durationInFrames + 40}>+ <Sequence from={0 - 40} durationInFrames={durationInFrames + 40}><Video src={video} /></Sequence></div>