Skip to content

🎥 Make videos programmatically with React

`@remotion/web-renderer`: Add test verifying frameRange duration correctness

Jonny Burgercbc6113c0dbf
diff --git a/packages/web-renderer/src/test/frame-range.test.tsx b/packages/web-renderer/src/test/frame-range.test.tsx
index 52db2b6bae..33c329daf7 100644
--- a/packages/web-renderer/src/test/frame-range.test.tsx
+++ b/packages/web-renderer/src/test/frame-range.test.tsx
@@ -1,3 +1,4 @@
+import {ALL_FORMATS, BlobSource, Input} from 'mediabunny';
import {expect, test} from 'vitest';
import type {RenderMediaOnWebProgress} from '../render-media-on-web';
import {renderMediaOnWeb} from '../render-media-on-web';
@@ -61,3 +62,44 @@ test('should render with valid frame range', async (t) => {
encodedFrames: 6,
});
});
+
+test('frameRange starting from non-zero should produce correct duration', async (t) => {
+ if (t.task.file.projectName === 'webkit') {
+ t.skip();
+ return;
+ }
+
+ const Component: React.FC = () => {
+ return null;
+ };
+
+ const fps = 30;
+ // Render only the back half: frames 10-19 = 10 frames
+ const frameRange: [number, number] = [10, 19];
+ const expectedFrames = frameRange[1] - frameRange[0] + 1;
+ const expectedDuration = expectedFrames / fps;
+
+ const result = await renderMediaOnWeb({
+ composition: {
+ component: Component,
+ id: 'frame-range-duration-test',
+ width: 100,
+ height: 100,
+ fps,
+ durationInFrames: 20,
+ },
+ inputProps: {},
+ frameRange,
+ outputTarget: 'arraybuffer',
+ licenseKey: 'free-license',
+ });
+
+ const blob = await result.getBlob();
+ using input = new Input({
+ formats: ALL_FORMATS,
+ source: new BlobSource(blob),
+ });
+
+ const duration = await input.computeDuration();
+ expect(duration).toBeCloseTo(expectedDuration, 1);
+});