Skip to content

🎥 Make videos programmatically with React

fix regression: allow frame to be a float in spring()

Jonny Burgerc90fba85fa26
diff --git a/packages/cli/src/config/still-frame.ts b/packages/cli/src/config/still-frame.ts
index 56f13c5207..044f6700f2 100644
--- a/packages/cli/src/config/still-frame.ts
+++ b/packages/cli/src/config/still-frame.ts
@@ -3,7 +3,11 @@ import {Internals} from 'remotion';
let stillFrame = 0;
export const setStillFrame = (frame: number) => {
- Internals.validateFrame(frame, Infinity);
+ Internals.validateFrame({
+ frame,
+ durationInFrames: Infinity,
+ allowFloats: false,
+ });
stillFrame = frame;
};
diff --git a/packages/core/src/spring/index.ts b/packages/core/src/spring/index.ts
index d976597f7b..5a289c4463 100644
--- a/packages/core/src/spring/index.ts
+++ b/packages/core/src/spring/index.ts
@@ -38,7 +38,7 @@ export function spring({
durationRestThreshold?: number;
}): number {
validateSpringDuration(durationInFrames);
- validateFrame(frame, Infinity);
+ validateFrame({frame, durationInFrames: Infinity, allowFloats: true});
validateFps(fps, 'to spring()', false);
const durationRatio =
diff --git a/packages/core/src/validate-frame.ts b/packages/core/src/validate-frame.ts
index cb5830351b..6985a2180a 100644
--- a/packages/core/src/validate-frame.ts
+++ b/packages/core/src/validate-frame.ts
@@ -1,4 +1,12 @@
-export const validateFrame = (frame: number, durationInFrames: number) => {
+export const validateFrame = ({
+ allowFloats,
+ durationInFrames,
+ frame,
+}: {
+ frame: number;
+ durationInFrames: number;
+ allowFloats: boolean;
+}) => {
if (typeof frame === 'undefined') {
throw new TypeError(`Argument missing for parameter "frame"`);
}
@@ -13,7 +21,7 @@ export const validateFrame = (frame: number, durationInFrames: number) => {
throw new RangeError(`Frame ${frame} is not finite`);
}
- if (frame % 1 !== 0) {
+ if (frame % 1 !== 0 && !allowFloats) {
throw new RangeError(
`Argument for frame must be an integer, but got ${frame}`
);
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 446215e8a0..0517245f53 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -109,7 +109,11 @@ const innerRenderStill = async ({
allowFloats: false,
});
validateNonNullImageFormat(imageFormat);
- Internals.validateFrame(frame, composition.durationInFrames);
+ Internals.validateFrame({
+ frame,
+ durationInFrames: composition.durationInFrames,
+ allowFloats: false,
+ });
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 4cafb555ac..23b58ce08b 100644
--- a/packages/renderer/src/test/frame.test.ts
+++ b/packages/renderer/src/test/frame.test.ts
@@ -2,24 +2,68 @@ import {Internals} from 'remotion';
import {expect, test} from 'vitest';
test('Validate frame', () => {
- expect(() => Internals.validateFrame(Infinity, 100)).toThrow(
- /Frame Infinity is not finite/
- );
- expect(
- // @ts-expect-error
- () => Internals.validateFrame('hithere', 100)
+ expect(() =>
+ Internals.validateFrame({
+ durationInFrames: Infinity,
+ frame: 100,
+ allowFloats: false,
+ })
+ ).toThrow(/Frame Infinity is not finite/);
+ expect(() =>
+ Internals.validateFrame({
+ // @ts-expect-error
+ frame: 'hithere',
+ allowFloats: false,
+ durationInFrames: 100,
+ })
).toThrow(/Argument passed for "frame" is not a number: hithere/);
- expect(() => Internals.validateFrame(3, 1)).toThrow(
+ expect(() =>
+ Internals.validateFrame({frame: 3, durationInFrames: 1, allowFloats: true})
+ ).toThrow(
/Cannot use frame 3: Duration of composition is 1, therefore the highest frame that can be rendered is 0/
);
- expect(() => Internals.validateFrame(2.99, 10)).toThrow(
- /Argument for frame must be an integer, but got 2.99/
- );
- 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(
+ expect(() =>
+ Internals.validateFrame({
+ frame: 2.99,
+ durationInFrames: 10,
+ allowFloats: false,
+ })
+ ).toThrow(/Argument for frame must be an integer, but got 2.99/);
+ expect(() =>
+ Internals.validateFrame({
+ frame: 2.99,
+ durationInFrames: 10,
+ allowFloats: true,
+ })
+ ).not.toThrow();
+
+ expect(() =>
+ Internals.validateFrame({frame: 0, durationInFrames: 1, allowFloats: false})
+ ).not.toThrow();
+ expect(() =>
+ Internals.validateFrame({frame: 1, durationInFrames: 2, allowFloats: false})
+ ).not.toThrow();
+ expect(() =>
+ Internals.validateFrame({
+ frame: -1,
+ durationInFrames: 100,
+ allowFloats: false,
+ })
+ ).not.toThrow();
+ expect(() =>
+ Internals.validateFrame({
+ frame: -100,
+ durationInFrames: 100,
+ allowFloats: false,
+ })
+ ).not.toThrow();
+ expect(() =>
+ Internals.validateFrame({
+ frame: -101,
+ durationInFrames: 100,
+ allowFloats: false,
+ })
+ ).toThrow(
/Cannot use frame -101: Duration of composition is 100, therefore the lowest frame that can be rendered is -100/
);
});