Skip to content

🎥 Make videos programmatically with React

timeline fixes

Jonny Burgerac02c7bee5cd
diff --git a/packages/cli/src/editor/components/PlayPause.tsx b/packages/cli/src/editor/components/PlayPause.tsx
index bbb0de0b41..d409d8f60e 100644
--- a/packages/cli/src/editor/components/PlayPause.tsx
+++ b/packages/cli/src/editor/components/PlayPause.tsx
@@ -40,7 +40,7 @@ export const PlayPause: React.FC = () => {
setFrame((f) => f - 1);
}, [frame, playing, setFrame, video]);
- const isLastFrame = frame === (config?.durationInFrames ?? 1);
+ const isLastFrame = frame === (config?.durationInFrames ?? 1) - 1;
const frameForward = useCallback(() => {
if (!video) {
diff --git a/packages/cli/src/editor/components/TimelineSlider.tsx b/packages/cli/src/editor/components/TimelineSlider.tsx
index ca5177ae1e..bd133ced9b 100644
--- a/packages/cli/src/editor/components/TimelineSlider.tsx
+++ b/packages/cli/src/editor/components/TimelineSlider.tsx
@@ -1,4 +1,4 @@
-import React, {useMemo} from 'react';
+import React from 'react';
import {Internals} from 'remotion';
import styled from 'styled-components';
import {
@@ -8,9 +8,12 @@ import {
import {useWindowSize} from '../hooks/use-window-size';
import {TimelineSliderHandle} from './TimelineSliderHandle';
-const Container = styled.div`
+const Container = styled.div<{
+ leftAmount: number;
+}>`
position: absolute;
top: 0;
+ left: ${(props) => props.leftAmount}px;
`;
const Line = styled.div`
@@ -25,27 +28,17 @@ export const TimelineSlider: React.FC = () => {
const videoConfig = Internals.useUnsafeVideoConfig();
const {width} = useWindowSize();
- const left = useMemo(() => {
- if (!videoConfig) {
- return 0;
- }
- return (
- (timelinePosition / videoConfig.durationInFrames) *
- (width - TIMELINE_LEFT_PADDING - TIMELINE_RIGHT_PADDING - 1) +
- TIMELINE_LEFT_PADDING
- );
- }, [timelinePosition, videoConfig, width]);
-
if (!videoConfig) {
return null;
}
+ const left =
+ (timelinePosition / (videoConfig.durationInFrames - 1)) *
+ (width - TIMELINE_LEFT_PADDING - TIMELINE_RIGHT_PADDING - 1) +
+ TIMELINE_LEFT_PADDING;
+
return (
- <Container
- style={{
- left,
- }}
- >
+ <Container leftAmount={left}>
<Line>
<TimelineSliderHandle />
</Line>
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index 59dd5bf713..a4940a3c71 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -27,14 +27,16 @@ 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);
if (!playing || absoluteFrame === 0) {
- videoRef.current.currentTime = currentFrame / (1000 / videoConfig.fps);
+ videoRef.current.currentTime = currentTime;
return;
}
if (videoRef.current.paused) {
- videoRef.current.currentTime = currentFrame / (1000 / videoConfig.fps);
+ videoRef.current.currentTime = currentTime;
videoRef.current.play();
}
}, [currentFrame, playing, videoConfig, absoluteFrame]);
diff --git a/packages/example/src/AudioTesting/framer.mp4 b/packages/example/src/AudioTesting/framer.mp4
new file mode 100644
index 0000000000..dade29dc08
Binary files /dev/null and b/packages/example/src/AudioTesting/framer.mp4 differ
diff --git a/packages/example/src/AudioTesting/index.tsx b/packages/example/src/AudioTesting/index.tsx
new file mode 100644
index 0000000000..bd809db788
--- /dev/null
+++ b/packages/example/src/AudioTesting/index.tsx
@@ -0,0 +1,13 @@
+import {Sequence, useVideoConfig, Video} from 'remotion';
+import video from './framer.mp4';
+
+export const AudioTesting: React.FC = () => {
+ const {durationInFrames} = useVideoConfig();
+ return (
+ <div>
+ <Sequence from={0} durationInFrames={durationInFrames + 40}>
+ <Video src={video} />
+ </Sequence>
+ </div>
+ );
+};
diff --git a/packages/example/src/Framer/index.tsx b/packages/example/src/Framer/index.tsx
new file mode 100644
index 0000000000..aaf2f1e714
--- /dev/null
+++ b/packages/example/src/Framer/index.tsx
@@ -0,0 +1,18 @@
+import {useCurrentFrame} from 'remotion';
+
+export const Framer: React.FC = () => {
+ const frame = useCurrentFrame();
+ return (
+ <div
+ style={{
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ background: 'white',
+ flex: 1,
+ }}
+ >
+ <h1 style={{fontSize: 120}}>{frame}</h1>
+ </div>
+ );
+};
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index b64d34707f..a1988f498c 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -1,5 +1,7 @@
import React from 'react';
import {Composition} from 'remotion';
+import {AudioTesting} from './AudioTesting';
+import {Framer} from './Framer';
import {MissingImg} from './MissingImg';
import {TenFrameTester} from './TenFrameTester';
@@ -146,6 +148,22 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={10}
/>
+ <Composition
+ id="audio-testing"
+ component={AudioTesting}
+ width={1080}
+ height={1080}
+ fps={30}
+ durationInFrames={1}
+ />
+ <Composition
+ id="framer"
+ component={Framer}
+ width={1080}
+ height={1080}
+ fps={30}
+ durationInFrames={100}
+ />
</>
);
};