Skip to content

🎥 Make videos programmatically with React

progress

Jonny Burger900fca694de6
diff --git a/packages/docs/components/LambdaSplash/VideoApps.tsx b/packages/docs/components/LambdaSplash/VideoApps.tsx
index 6526d57962..dd247b7811 100644
--- a/packages/docs/components/LambdaSplash/VideoApps.tsx
+++ b/packages/docs/components/LambdaSplash/VideoApps.tsx
@@ -1,15 +1,15 @@
import {useColorMode} from '@docusaurus/theme-common';
import React, {useEffect, useState} from 'react';
import {BlueButton} from '../layout/Button';
-import {BOX_STROKE} from '../layout/colors';
+import {PALETTE} from '../layout/colors';
import {Spacer} from '../layout/Spacer';
import videoapps from './videoapps.module.css';
import {YouAreHere} from './YouAreHere';
const panel: React.CSSProperties = {
backgroundColor: 'var(--ifm-background-color)',
- border: '2px solid ' + BOX_STROKE,
- borderBottom: '4px solid ' + BOX_STROKE,
+ border: '2px solid ' + PALETTE.BOX_STROKE,
+ borderBottom: '4px solid ' + PALETTE.BOX_STROKE,
padding: 10,
borderRadius: 15,
flex: 1,
diff --git a/packages/docs/components/layout/colors.ts b/packages/docs/components/layout/colors.ts
index 5e49838870..4b6bc05d6d 100644
--- a/packages/docs/components/layout/colors.ts
+++ b/packages/docs/components/layout/colors.ts
@@ -1,10 +1,13 @@
import {darken, transparentize} from 'polished';
-export const LIGHT_BLUE = '#42e9f5';
-export const DARK_BLUE = '#4290f5';
-export const UNDERLAY_BLUE = transparentize(0.85, DARK_BLUE);
+export const PALETTE = {
+ BOX_STROKE: 'var(--box-stroke)',
+ TEXT_COLOR: 'var(--text-color)',
+ BORDER_COLOR: 'var(--border-color)',
+ BRAND: 'var(--ifm-color-primary)',
+};
+
+export const UNDERLAY_BLUE = transparentize(0.85, PALETTE.BRAND);
export const RED = '#e74c3c';
export const UNDERLAY_RED = transparentize(0.9, RED);
-export const BLUE_TEXT = darken(0.3, DARK_BLUE);
-
-export const BOX_STROKE = 'var(--box-stroke)';
+export const BLUE_TEXT = darken(0.3, PALETTE.BRAND);
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsx
index f5529687f0..a88fb3d874 100644
--- a/packages/docs/src/components/Demo/Demo.tsx
+++ b/packages/docs/src/components/Demo/Demo.tsx
@@ -11,7 +11,7 @@ import React, {
useState,
} from 'react';
import {staticFile} from 'remotion';
-import {BOX_STROKE} from '../../../components/layout/colors';
+import {PALETTE} from '../../../components/layout/colors';
import type {
DemoPlayerProps,
LocationAndTrending,
@@ -31,13 +31,13 @@ preloadAudio(staticFile('Utope-nature-5s.mp3'));
const style: React.CSSProperties = {
width: '100%',
aspectRatio: '640 / 360',
- borderBottom: `2px solid ${BOX_STROKE}`,
+ borderBottom: `2px solid ${PALETTE.BOX_STROKE}`,
touchAction: 'none', // prevent page from scrolling when dragging children on mobile
};
const playerWrapper: CSSProperties = {
- border: `2px solid ${BOX_STROKE}`,
- borderBottom: `4px solid ${BOX_STROKE}`,
+ border: `2px solid ${PALETTE.BOX_STROKE}`,
+ borderBottom: `4px solid ${PALETTE.BOX_STROKE}`,
borderRadius: 8,
width: '100%',
overflow: 'hidden',
diff --git a/packages/docs/src/components/Demo/DemoRender.tsx b/packages/docs/src/components/Demo/DemoRender.tsx
index 34024b594b..36c33f0542 100644
--- a/packages/docs/src/components/Demo/DemoRender.tsx
+++ b/packages/docs/src/components/Demo/DemoRender.tsx
@@ -1,6 +1,9 @@
import type {EnhancedErrorInfo} from '@remotion/lambda';
import React, {useCallback} from 'react';
import {z} from 'zod';
+import {DoneCheckmark} from './DoneCheckmark';
+import {Progress} from './Progress';
+import {Spinner} from './Spinner';
const countryPath = z.object({
d: z.string(),
@@ -50,15 +53,20 @@ const style: React.CSSProperties = {
border: 'none',
outline: 'none',
backgroundColor: 'transparent',
- paddingLeft: 16,
- paddingRight: 16,
cursor: 'pointer',
+ width: 55,
+ height: 50,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
};
export const RenderButton: React.FC<{
renderData: z.infer<typeof data> | null;
}> = ({renderData}) => {
- const [state, setState] = React.useState<State>({type: 'idle'});
+ const [state, setState] = React.useState<State>({
+ type: 'idle',
+ });
const triggerRender = useCallback(async () => {
if (renderData === null) {
@@ -74,7 +82,8 @@ export const RenderButton: React.FC<{
body: JSON.stringify(renderData),
})
).json();
- console.log({renderId, bucketName});
+ setState({type: 'progress', progress: 0});
+
let done = false;
while (!done) {
@@ -90,14 +99,21 @@ export const RenderButton: React.FC<{
errors: EnhancedErrorInfo[];
fatalErrorEncountered: boolean;
};
+ setState({
+ type: 'progress',
+ progress: progress.overallProgress,
+ });
console.log({progress});
- if (progress.outputFile || progress.fatalErrorEncountered) {
+ if (progress.outputFile) {
done = true;
+ setState({type: 'done'});
}
- }
- setState({type: 'progress', progress: 0});
+ if (progress.fatalErrorEncountered) {
+ done = true;
+ }
+ }
}, [renderData]);
return (
@@ -107,16 +123,24 @@ export const RenderButton: React.FC<{
style={style}
disabled={!renderData}
>
- <svg
- style={{
- width: 18,
- opacity: renderData ? 1 : 0.5,
- }}
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 384 512"
- >
- <path d="M214.6 342.6L192 365.3l-22.6-22.6-128-128L18.7 192 64 146.7l22.6 22.6L160 242.7 160 64l0-32 64 0 0 32 0 178.7 73.4-73.4L320 146.7 365.3 192l-22.6 22.6-128 128zM32 416l320 0 32 0 0 64-32 0L32 480 0 480l0-64 32 0z" />
- </svg>
+ {state.type === 'done' ? (
+ <DoneCheckmark />
+ ) : state.type === 'progress' ? (
+ <Progress progress={state.progress} />
+ ) : state.type === 'invoking' ? (
+ <Spinner size={20} duration={1} />
+ ) : (
+ <svg
+ style={{
+ width: 18,
+ opacity: renderData ? 1 : 0.5,
+ }}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 384 512"
+ >
+ <path d="M214.6 342.6L192 365.3l-22.6-22.6-128-128L18.7 192 64 146.7l22.6 22.6L160 242.7 160 64l0-32 64 0 0 32 0 178.7 73.4-73.4L320 146.7 365.3 192l-22.6 22.6-128 128zM32 416l320 0 32 0 0 64-32 0L32 480 0 480l0-64 32 0z" />
+ </svg>
+ )}
</button>
);
};
diff --git a/packages/docs/src/components/Demo/DoneCheckmark.tsx b/packages/docs/src/components/Demo/DoneCheckmark.tsx
new file mode 100644
index 0000000000..fababf4fa3
--- /dev/null
+++ b/packages/docs/src/components/Demo/DoneCheckmark.tsx
@@ -0,0 +1,34 @@
+import React from 'react';
+import {PALETTE} from '../../../components/layout/colors';
+
+export const DoneCheckmark: React.FC = () => {
+ return (
+ <div
+ style={{
+ backgroundColor: PALETTE.BRAND,
+ height: 22,
+ width: 22,
+ borderRadius: 11,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}
+ >
+ <svg
+ viewBox="0 0 20 20"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ style={{
+ flexShrink: 0,
+ width: 22,
+ }}
+ >
+ <circle cx="10" cy="10" r="10" fill="#0B84F3" />
+ <path
+ d="M14.7908 7.20505C15.0697 7.47844 15.0697 7.92243 14.7908 8.19583L9.07711 13.795C8.79813 14.0683 8.34505 14.0683 8.06606 13.795L5.20924 10.9954C4.93025 10.722 4.93025 10.278 5.20924 10.0046C5.48823 9.73121 5.9413 9.73121 6.22029 10.0046L8.5727 12.3077L13.7819 7.20505C14.0609 6.93165 14.514 6.93165 14.793 7.20505H14.7908Z"
+ fill="white"
+ />
+ </svg>{' '}
+ </div>
+ );
+};
diff --git a/packages/docs/src/components/Demo/PlayerControls.tsx b/packages/docs/src/components/Demo/PlayerControls.tsx
index 86509c71f2..30030df48d 100644
--- a/packages/docs/src/components/Demo/PlayerControls.tsx
+++ b/packages/docs/src/components/Demo/PlayerControls.tsx
@@ -1,6 +1,6 @@
import type {PlayerRef} from '@remotion/player';
import React from 'react';
-import {BOX_STROKE} from '../../../components/layout/colors';
+import {PALETTE} from '../../../components/layout/colors';
import styles from './player.module.css';
import {PlayerSeekBar} from './PlayerSeekBar';
import {PlayerVolume} from './PlayerVolume';
@@ -11,7 +11,7 @@ const Separator: React.FC = () => {
return (
<div
style={{
- borderRight: `2px solid ${BOX_STROKE}`,
+ borderRight: `2px solid ${PALETTE.BOX_STROKE}`,
height: 50,
}}
/>
@@ -26,28 +26,24 @@ export const PlayerControls: React.FC<{
}> = ({playerRef, durationInFrames, fps, children}) => {
return (
<div className={styles['controls-wrapper']}>
- <div className={styles['start-controls']}>
- <PlayPauseButton playerRef={playerRef} />
- <Separator />
- <PlayerVolume playerRef={playerRef} />
- <Separator />
- <div style={{width: 15}} />
- <TimeDisplay playerRef={playerRef} fps={fps} />
- <div style={{width: 15}} />
- <PlayerSeekBar
- durationInFrames={durationInFrames}
- playerRef={playerRef}
- inFrame={null}
- outFrame={null}
- onSeekEnd={() => undefined}
- onSeekStart={() => undefined}
- />
- <div style={{width: 20}} />
- </div>
- <div className={styles['end-controls']}>
- <Separator />
- {children}
- </div>
+ <PlayPauseButton playerRef={playerRef} />
+ <Separator />
+ <PlayerVolume playerRef={playerRef} />
+ <Separator />
+ <div style={{width: 15}} />
+ <TimeDisplay playerRef={playerRef} fps={fps} />
+ <div style={{width: 15}} />
+ <PlayerSeekBar
+ durationInFrames={durationInFrames}
+ playerRef={playerRef}
+ inFrame={null}
+ outFrame={null}
+ onSeekEnd={() => undefined}
+ onSeekStart={() => undefined}
+ />
+ <div style={{width: 20}} />
+ <Separator />
+ {children}
</div>
);
};
diff --git a/packages/docs/src/components/Demo/Progress.tsx b/packages/docs/src/components/Demo/Progress.tsx
new file mode 100644
index 0000000000..13d25c4f05
--- /dev/null
+++ b/packages/docs/src/components/Demo/Progress.tsx
@@ -0,0 +1,38 @@
+import {makeCircle, makePie} from '@remotion/shapes';
+import React from 'react';
+import {PALETTE} from '../../../components/layout/colors';
+
+export const Progress: React.FC<{
+ progress: number;
+}> = ({progress}) => {
+ const inner = makeCircle({
+ radius: 10,
+ });
+
+ const outer = makePie({
+ progress,
+ closePath: false,
+ radius: 10,
+ });
+
+ return (
+ <svg
+ viewBox={`0 0 ${inner.width} ${inner.height}`}
+ style={{overflow: 'visible', height: 22}}
+ >
+ <path
+ d={inner.path}
+ stroke={PALETTE.BORDER_COLOR}
+ strokeWidth={4}
+ fill="transparent"
+ />
+ <path
+ d={outer.path}
+ stroke={PALETTE.BRAND}
+ strokeWidth={4}
+ fill="transparent"
+ strokeLinecap="round"
+ />
+ </svg>
+ );
+};
diff --git a/packages/docs/src/components/Demo/Spinner.tsx b/packages/docs/src/components/Demo/Spinner.tsx
new file mode 100644
index 0000000000..ac99d54197
--- /dev/null
+++ b/packages/docs/src/components/Demo/Spinner.tsx
@@ -0,0 +1,60 @@
+import React, {useMemo} from 'react';
+import {PALETTE} from '../../../components/layout/colors';
+
+const viewBox = 100;
+const lines = 8;
+const className = '__remotion_spinner_line';
+const remotionSpinnerAnimation = '__remotion_spinner_animation';
+
+// Generated from https://github.com/remotion-dev/template-next/commit/9282c93f7c51ada31a42e18a94680fa09a14eee3
+const translated =
+ 'M 44 0 L 50 0 a 6 6 0 0 1 6 6 L 56 26 a 6 6 0 0 1 -6 6 L 50 32 a 6 6 0 0 1 -6 -6 L 44 6 a 6 6 0 0 1 6 -6 Z';
+
+export const Spinner: React.FC<{
+ readonly size: number;
+ readonly duration: number;
+}> = ({size, duration}) => {
+ const style = useMemo(() => {
+ return {
+ width: size,
+ height: size,
+ };
+ }, [size]);
+
+ return (
+ <>
+ <style type="text/css">{`
+ @keyframes ${remotionSpinnerAnimation} {
+ 0% {
+ opacity: 1;
+ }
+ 100% {
+ opacity: 0.15;
+ }
+ }
+
+ .${className} {
+ animation: ${remotionSpinnerAnimation} ${duration}s linear infinite;
+ }
+ `}</style>
+ <svg style={style} viewBox={`0 0 ${viewBox} ${viewBox}`}>
+ {new Array(lines).fill(true).map((_, index) => {
+ return (
+ <path
+ // eslint-disable-next-line react/no-array-index-key
+ key={index}
+ className={className}
+ style={{
+ rotate: `${(index * Math.PI * 2) / lines}rad`,
+ transformOrigin: 'center center',
+ animationDelay: `${index * (duration / lines) - duration}s`,
+ }}
+ d={translated}
+ fill={PALETTE.TEXT_COLOR}
+ />
+ );
+ })}
+ </svg>
+ </>
+ );
+};
diff --git a/packages/docs/src/components/Demo/player.module.css b/packages/docs/src/components/Demo/player.module.css
index 4c8b73ae49..388d572262 100644
--- a/packages/docs/src/components/Demo/player.module.css
+++ b/packages/docs/src/components/Demo/player.module.css
@@ -5,25 +5,6 @@
border-radius: 0.5rem;
}
-.controls-wrapper .start-controls {
- display: flex;
- flex-direction: row;
- align-items: center;
- width: 100%;
-}
-
-.controls-wrapper .end-controls {
- display: flex;
- flex-direction: row;
- align-items: center;
-}
-
-@media screen and (min-width: 901px) {
- .end-controls {
- height: 100%;
- }
-}
-
.volume-button {
position: relative;
cursor: pointer;
diff --git a/packages/docs/src/components/ExpertPage.tsx b/packages/docs/src/components/ExpertPage.tsx
index 4b39f87443..47e7a918e9 100644
--- a/packages/docs/src/components/ExpertPage.tsx
+++ b/packages/docs/src/components/ExpertPage.tsx
@@ -4,10 +4,10 @@ import Layout from '@theme/Layout';
import React from 'react';
import {Button} from '../../components/layout/Button';
import {Spacer} from '../../components/layout/Spacer';
-import {DARK_BLUE} from '../../components/layout/colors';
import {experts} from '../data/experts';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
+import {PALETTE} from '../../components/layout/colors';
import {BackButton} from './BackButton';
import {Seo} from './Seo';
@@ -19,7 +19,7 @@ const layout: React.CSSProperties = {
};
const header: React.CSSProperties = {
- backgroundColor: DARK_BLUE,
+ backgroundColor: PALETTE.BRAND,
color: 'white',
paddingTop: 15,
};
@@ -58,7 +58,7 @@ const description: React.CSSProperties = {
};
const socialIcon: React.CSSProperties = {
- color: DARK_BLUE,
+ color: PALETTE.BRAND,
height: 24,
};