Skip to content

🎥 Make videos programmatically with React

WIP

Jonny Burger3c92b0cc7d6b
diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsx
index d7fdccbae3..085bb032d0 100644
--- a/packages/transitions/src/TransitionSeries.tsx
+++ b/packages/transitions/src/TransitionSeries.tsx
@@ -3,12 +3,15 @@ import {
Internals,
Sequence,
SequenceProps,
- spring,
useCurrentFrame,
useVideoConfig,
} from 'remotion';
import {flattenChildren} from './flatten-children';
-import {getTransitionDuration, SPRING_THRESHOLD} from './timing';
+import {
+ getTransitionDuration,
+ springWithRoundUpIfThreshold,
+ SPRING_THRESHOLD,
+} from './timing';
import {
TransitionSeriesTransition,
TransitionSeriesTransitionProps,
@@ -27,22 +30,6 @@ const SeriesSequence = ({children}: SeriesSequenceProps) => {
return <>{children}</>;
};
-export const springWithRoundUpIfThreshold: typeof spring = (args) => {
- if (args.to || args.from) {
- throw new Error(
- 'to / from values are not supported by springWithRoundUpIfThreshold'
- );
- }
-
- const spr = spring(args);
-
- if (spr > 1 - SPRING_THRESHOLD) {
- return 1;
- }
-
- return spr;
-};
-
type TransitionType = {
props: TransitionSeriesTransitionProps;
type: typeof TransitionSeriesTransition;
@@ -189,6 +176,7 @@ const TransitionSeries: FC<{
})
: null;
+ // TODO: getProgress
const prevProgress = prev
? springWithRoundUpIfThreshold({
fps,
diff --git a/packages/transitions/src/timing.ts b/packages/transitions/src/timing.ts
index 34d4b1a132..2ce8e71781 100644
--- a/packages/transitions/src/timing.ts
+++ b/packages/transitions/src/timing.ts
@@ -1,4 +1,4 @@
-import {measureSpring, SpringConfig} from 'remotion';
+import {measureSpring, spring, SpringConfig} from 'remotion';
export type TransitionTiming = {
type: 'spring';
@@ -21,3 +21,33 @@ export const getTransitionDuration = (
throw new TypeError('Unsupported transition type: ' + timing.type);
};
+
+export const springWithRoundUpIfThreshold: typeof spring = (args) => {
+ if (args.to || args.from) {
+ throw new Error(
+ 'to / from values are not supported by springWithRoundUpIfThreshold'
+ );
+ }
+
+ const spr = spring(args);
+
+ if (spr > 1 - SPRING_THRESHOLD) {
+ return 1;
+ }
+
+ return spr;
+};
+
+export const getProgress = (
+ frame: number,
+ fps: number,
+ timing: TransitionTiming
+) => {
+ if (timing.type === 'spring') {
+ return springWithRoundUpIfThreshold({
+ fps,
+ frame,
+ config: timing.config,
+ });
+ }
+};