Skip to content

🎥 Make videos programmatically with React

hmm fix

JonnyBurgerdb57ddbf1606
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsx
index 72efcd2de5..87ce802c3d 100644
--- a/packages/core/src/audio/Audio.tsx
+++ b/packages/core/src/audio/Audio.tsx
@@ -120,10 +120,10 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
<Loop
layout="none"
durationInFrames={calculateLoopDuration({
- endAt: trimAfterValue,
+ trimAfter: trimAfterValue,
mediaDurationInFrames: duration,
playbackRate: props.playbackRate ?? 1,
- startFrom: trimBeforeValue,
+ trimBefore: trimBeforeValue,
})}
>
<Audio
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsx
index fe3f89226e..5e46e29c4e 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/Video.tsx
@@ -98,10 +98,10 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
return (
<Loop
durationInFrames={calculateLoopDuration({
- endAt: trimAfterValue,
+ trimAfter: trimAfterValue,
mediaDurationInFrames: mediaDuration,
playbackRate: props.playbackRate ?? 1,
- startFrom: trimBeforeValue,
+ trimBefore: trimBeforeValue,
})}
layout="none"
name={name}
diff --git a/packages/media/src/extract-frame-and-audio.ts b/packages/media/src/extract-frame-and-audio.ts
index 9e06afa833..6a3d1a8799 100644
--- a/packages/media/src/extract-frame-and-audio.ts
+++ b/packages/media/src/extract-frame-and-audio.ts
@@ -38,7 +38,7 @@ export const extractFrameAndAudio = async ({
timeInSeconds,
logLevel,
loop,
- trimAfter: trimAfter,
+ trimAfter,
playbackRate,
trimBefore,
fps,
diff --git a/packages/media/src/test/looping.test.ts b/packages/media/src/test/looping.test.ts
index 2c6624c1d1..5cd81c3b86 100644
--- a/packages/media/src/test/looping.test.ts
+++ b/packages/media/src/test/looping.test.ts
@@ -1,4 +1,5 @@
import {assert, expect, test} from 'vitest';
+import {getTimeInSeconds} from '../get-time-in-seconds';
import {extractFrame} from '../video-extraction/extract-frame';
const fps = 25;
@@ -8,13 +9,26 @@ const playbackRate = 2;
const loop = true;
test('when looping with a lot of concurrency, it must be frame-accurate', async () => {
- const letInputTimestamps = [1.96, 2, 2.04, 2.08];
+ const letInputTimestamps = [198, 199, 200, 201, 202];
+ const realTimestamps = [];
const outputTimestamps = [];
- for (const timeInSeconds of letInputTimestamps) {
+ for (const timeInFrames of letInputTimestamps) {
+ const realTimestamp = getTimeInSeconds({
+ fps,
+ loop,
+ mediaDurationInSeconds: 10,
+ playbackRate,
+ src: 'https://remotion.media/video.mp4',
+ trimAfter,
+ trimBefore,
+ unloopedTimeInSeconds: timeInFrames / fps,
+ });
+ realTimestamps.push(realTimestamp);
+
const result = await extractFrame({
src: 'https://remotion.media/video.mp4',
- timeInSeconds,
+ timeInSeconds: timeInFrames / fps,
logLevel: 'verbose',
loop,
trimAfter,
@@ -27,5 +41,6 @@ test('when looping with a lot of concurrency, it must be frame-accurate', async
outputTimestamps.push(result.frame?.timestamp ?? 0);
}
- expect(outputTimestamps).toEqual([4, 4, 4, 4]);
+ expect(realTimestamps).toEqual([7.96, 7.98, 4, 4.02, 4.04]);
+ expect(outputTimestamps).toEqual([7.96, 7.98, 4, 4.02, 4.04]);
});