Skip to content

🎥 Make videos programmatically with React

further testign

Jonny Burger863ea71ced9f
diff --git a/packages/media/src/audio-extraction/audio-manager.ts b/packages/media/src/audio-extraction/audio-manager.ts
index 8a957369da..2187762729 100644
--- a/packages/media/src/audio-extraction/audio-manager.ts
+++ b/packages/media/src/audio-extraction/audio-manager.ts
@@ -95,8 +95,24 @@ export const makeAudioManager = () => {
logLevel: LogLevel;
maxCacheSize: number;
}) => {
- while ((await getTotalCacheStats()).totalSize > maxCacheSize) {
+ let attempts = 0;
+ const maxAttempts = 3;
+ while (
+ (await getTotalCacheStats()).totalSize > maxCacheSize &&
+ attempts < maxAttempts
+ ) {
deleteOldestIterator();
+ attempts++;
+ }
+
+ if (
+ (await getTotalCacheStats()).totalSize > maxCacheSize &&
+ attempts >= maxAttempts
+ ) {
+ Internals.Log.warn(
+ {logLevel, tag: '@remotion/media'},
+ `Audio cache: Exceeded max cache size after ${maxAttempts} attempts. Still ${(await getTotalCacheStats()).totalSize} bytes used, target was ${maxCacheSize} bytes.`,
+ );
}
for (const iterator of iterators) {
diff --git a/packages/media/src/caches.ts b/packages/media/src/caches.ts
index ab4636d841..aadaa593ff 100644
--- a/packages/media/src/caches.ts
+++ b/packages/media/src/caches.ts
@@ -4,7 +4,7 @@ import {makeAudioManager} from './audio-extraction/audio-manager';
import {makeKeyframeManager} from './video-extraction/keyframe-manager';
// Frames can be out of order, but we don't expect them to be more than 1 second out of order
-export const SAFE_WINDOW_OF_MONOTOCY = 1;
+export const SAFE_WINDOW_OF_MONOTOCY = 0.2;
export const keyframeManager = makeKeyframeManager();
export const audioManager = makeAudioManager();
diff --git a/packages/media/src/video-extraction/get-frames-since-keyframe.ts b/packages/media/src/video-extraction/get-frames-since-keyframe.ts
index 592da44bba..c462e7d972 100644
--- a/packages/media/src/video-extraction/get-frames-since-keyframe.ts
+++ b/packages/media/src/video-extraction/get-frames-since-keyframe.ts
@@ -187,7 +187,7 @@ export const getFramesSinceKeyframe = async ({
);
const keyframeBank = makeKeyframeBank({
- startTimestampInSeconds: startPacket.timestamp,
+ startTimestampInSeconds: roundTo4Digits(requestedTimestamp),
endTimestampInSeconds: nextKeyPacket ? nextKeyPacket.timestamp : Infinity,
sampleIterator,
logLevel,
diff --git a/packages/media/src/video-extraction/keyframe-bank.ts b/packages/media/src/video-extraction/keyframe-bank.ts
index c99ac14080..8fe1242e41 100644
--- a/packages/media/src/video-extraction/keyframe-bank.ts
+++ b/packages/media/src/video-extraction/keyframe-bank.ts
@@ -155,13 +155,6 @@ export const makeKeyframeBank = ({
// Test case: https://github.com/remotion-dev/remotion/issues/5915
let adjustedTimestamp = timestampInSeconds;
- if (
- roundTo4Digits(timestampInSeconds) <
- roundTo4Digits(startTimestampInSeconds)
- ) {
- adjustedTimestamp = startTimestampInSeconds;
- }
-
// If we request a timestamp after the end of the video, return the last frame
// same behavior as <video>
if (
@@ -188,7 +181,8 @@ export const makeKeyframeBank = ({
}
}
- return null;
+ // Return first frame we have
+ return frames[frameTimestamps[0]] ?? null;
};
const hasTimestampInSecond = async (timestamp: number) => {
diff --git a/packages/media/src/video-extraction/keyframe-manager.ts b/packages/media/src/video-extraction/keyframe-manager.ts
index e86bc5cbc7..38b4f4724f 100644
--- a/packages/media/src/video-extraction/keyframe-manager.ts
+++ b/packages/media/src/video-extraction/keyframe-manager.ts
@@ -127,8 +127,10 @@ export const makeKeyframeManager = () => {
maxCacheSize: number,
) => {
let cacheStats = await getTotalCacheStats();
+ let attempts = 0;
+ const maxAttempts = 3;
- while (cacheStats.totalSize > maxCacheSize) {
+ while (cacheStats.totalSize > maxCacheSize && attempts < maxAttempts) {
const {finish} = await deleteOldestKeyframeBank(logLevel);
if (finish) {
break;
@@ -143,6 +145,14 @@ export const makeKeyframeManager = () => {
);
cacheStats = await getTotalCacheStats();
+ attempts++;
+ }
+
+ if (cacheStats.totalSize > maxCacheSize && attempts >= maxAttempts) {
+ Internals.Log.warn(
+ {logLevel, tag: '@remotion/media'},
+ `Exceeded max cache size after ${maxAttempts} attempts. Remaining cache size: ${(cacheStats.totalSize / 1024 / 1024).toFixed(1)} MB, target was ${(maxCacheSize / 1024 / 1024).toFixed(1)} MB.`,
+ );
}
};