Skip to content

🎥 Make videos programmatically with React

validate spring parameters

Jonny Burgercb39ce42099d
diff --git a/packages/astro-example/package.json b/packages/astro-example/package.json
index ea5d0ae5a2..cd2efffb6d 100644
--- a/packages/astro-example/package.json
+++ b/packages/astro-example/package.json
@@ -1,5 +1,6 @@
{
- "name": "short-solstice",
+ "name": "@remotion/astro-example",
+ "private": true,
"type": "module",
"version": "0.0.1",
"scripts": {
diff --git a/packages/cli/src/config/still-frame.ts b/packages/cli/src/config/still-frame.ts
index 0210555f45..56f13c5207 100644
--- a/packages/cli/src/config/still-frame.ts
+++ b/packages/cli/src/config/still-frame.ts
@@ -1,9 +1,9 @@
-import {RenderInternals} from '@remotion/renderer';
+import {Internals} from 'remotion';
let stillFrame = 0;
export const setStillFrame = (frame: number) => {
- RenderInternals.validateFrame(frame, Infinity);
+ Internals.validateFrame(frame, Infinity);
stillFrame = frame;
};
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index b776e80eeb..d2ee1a1da8 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -31,7 +31,10 @@ import {PrefetchProvider} from './prefetch-state.js';
import {getRoot, waitForRoot} from './register-root.js';
import {RemotionRoot} from './RemotionRoot.js';
import {SequenceContext} from './Sequence.js';
-import {ENV_VARIABLES_ENV_NAME, setupEnvVariables} from './setup-env-variables.js';
+import {
+ ENV_VARIABLES_ENV_NAME,
+ setupEnvVariables,
+} from './setup-env-variables.js';
import type {
SetTimelineContextValue,
TimelineContextValue,
@@ -41,6 +44,7 @@ import {truthy} from './truthy.js';
import {useLazyComponent} from './use-lazy-component.js';
import {useUnsafeVideoConfig} from './use-unsafe-video-config.js';
import {useVideo} from './use-video.js';
+import {validateFrame} from './validate-frame.js';
import {
invalidCompositionErrorMessage,
isCompositionIdValid,
@@ -109,6 +113,7 @@ export const Internals = {
IsPlayerContextProvider,
useIsPlayer,
useRemotionEnvironment,
+ validateFrame,
};
export type {
diff --git a/packages/core/src/spring/index.ts b/packages/core/src/spring/index.ts
index 4de5039333..287238a90d 100644
--- a/packages/core/src/spring/index.ts
+++ b/packages/core/src/spring/index.ts
@@ -1,3 +1,5 @@
+import {validateFrame} from '../validate-frame.js';
+import {validateFps} from '../validation/validate-fps.js';
import {validateSpringDuration} from '../validation/validation-spring-duration.js';
import {measureSpring} from './measure-spring.js';
import type {SpringConfig} from './spring-utils.js';
@@ -36,6 +38,8 @@ export function spring({
durationRestThreshold?: number;
}): number {
validateSpringDuration(durationInFrames);
+ validateFrame(frame, Infinity);
+ validateFps(fps, 'to spring()', false);
const durationRatio =
durationInFrames === undefined
diff --git a/packages/renderer/src/validate-frame.ts b/packages/core/src/validate-frame.ts
similarity index 100%
rename from packages/renderer/src/validate-frame.ts
rename to packages/core/src/validate-frame.ts
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 82ca0497c0..8c797332ff 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -48,7 +48,6 @@ import {tmpDir} from './tmp-dir';
import {validateConcurrency} from './validate-concurrency';
import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';
import {validateFfmpeg} from './validate-ffmpeg';
-import {validateFrame} from './validate-frame';
import {
DEFAULT_OPENGL_RENDERER,
validateOpenGlRenderer,
@@ -147,7 +146,6 @@ export const RenderInternals = {
validCodecs,
DEFAULT_PIXEL_FORMAT,
validateQuality,
- validateFrame,
DEFAULT_TIMEOUT,
DEFAULT_CODEC,
isAudioCodec,
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index ad6417d20d..830d8741cb 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -27,7 +27,6 @@ import {validateQuality} from './quality';
import {seekToFrame} from './seek-to-frame';
import {setPropsAndEnv} from './set-props-and-env';
import {takeFrameAndCompose} from './take-frame-and-compose';
-import {validateFrame} from './validate-frame';
import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
import {validateScale} from './validate-scale';
@@ -109,7 +108,7 @@ const innerRenderStill = async ({
'in the `config` object passed to `renderStill()`'
);
validateNonNullImageFormat(imageFormat);
- validateFrame(frame, composition.durationInFrames);
+ Internals.validateFrame(frame, composition.durationInFrames);
const stillFrame = convertToPositiveFrameIndex({
durationInFrames: composition.durationInFrames,
frame,
diff --git a/packages/renderer/src/test/frame.test.ts b/packages/renderer/src/test/frame.test.ts
index 1508bbd894..fe1b17b53e 100644
--- a/packages/renderer/src/test/frame.test.ts
+++ b/packages/renderer/src/test/frame.test.ts
@@ -1,25 +1,25 @@
+import {Internals} from 'remotion';
import {expect, test} from 'vitest';
-import {validateFrame} from '../validate-frame';
test('Validate frame', () => {
- expect(() => validateFrame(Infinity, 100)).toThrow(
+ expect(() => Internals.validateFrame(Infinity, 100)).toThrow(
/Frame Infinity is not finite/
);
expect(
// @ts-expect-error
() => validateFrame('hithere', 100)
).toThrow(/Argument passed for "frame" is not a number: hithere/);
- expect(() => validateFrame(3, 1)).toThrow(
+ expect(() => Internals.validateFrame(3, 1)).toThrow(
/Cannot use frame 3: Duration of composition is 1, therefore the highest frame that can be rendered is 0/
);
- expect(() => validateFrame(2.99, 10)).toThrow(
+ expect(() => Internals.validateFrame(2.99, 10)).toThrow(
/Argument for frame must be an integer, but got 2.99/
);
- expect(() => validateFrame(0, 1)).not.toThrow();
- expect(() => validateFrame(1, 2)).not.toThrow();
- expect(() => validateFrame(-1, 100)).not.toThrow();
- expect(() => validateFrame(-100, 100)).not.toThrow();
- expect(() => validateFrame(-101, 100)).toThrow(
+ expect(() => Internals.validateFrame(0, 1)).not.toThrow();
+ expect(() => Internals.validateFrame(1, 2)).not.toThrow();
+ expect(() => Internals.validateFrame(-1, 100)).not.toThrow();
+ expect(() => Internals.validateFrame(-100, 100)).not.toThrow();
+ expect(() => Internals.validateFrame(-101, 100)).toThrow(
/Cannot use frame -101: Duration of composition is 100, therefore the lowest frame that can be rendered is -100/
);
});