🎥 Make videos programmatically with React
`@remotion/media`: Don't call .allocationSize() if format is `null`
Jonny Burgerd9c620c7f71e
diff --git a/packages/media/src/video-extraction/get-allocation-size.ts b/packages/media/src/video-extraction/get-allocation-size.tsnew file mode 100644index 0000000000..c1f331d2bf--- /dev/null+++ b/packages/media/src/video-extraction/get-allocation-size.ts@@ -0,0 +1,9 @@+import type {VideoSample} from 'mediabunny';++export const getAllocationSize = (sample: VideoSample) => {+ if (sample.format === null) {+ return sample.codedHeight * sample.codedWidth * 4;+ }++ return sample.allocationSize();+};diff --git a/packages/media/src/video-extraction/keyframe-bank.ts b/packages/media/src/video-extraction/keyframe-bank.tsindex 8db61d23c7..2d671998bc 100644--- a/packages/media/src/video-extraction/keyframe-bank.ts+++ b/packages/media/src/video-extraction/keyframe-bank.ts@@ -3,6 +3,7 @@ import {Internals, type LogLevel} from 'remotion';import {SAFE_BACK_WINDOW_IN_SECONDS} from '../caches';import {roundTo4Digits} from '../helpers/round-to-4-digits';import {renderTimestampRange} from '../render-timestamp-range';+import {getAllocationSize} from './get-allocation-size';export type KeyframeBank = {src: string;@@ -71,7 +72,7 @@ export const makeKeyframeBank = ({continue;}- allocationSize -= frames[frameTimestamp].allocationSize();+ allocationSize -= getAllocationSize(frames[frameTimestamp]);frameTimestamps.splice(frameTimestamps.indexOf(frameTimestamp), 1);frames[frameTimestamp].close();@@ -109,7 +110,7 @@ export const makeKeyframeBank = ({const addFrame = (frame: VideoSample) => {frames[frame.timestamp] = frame;frameTimestamps.push(frame.timestamp);- allocationSize += frame.allocationSize();+ allocationSize += getAllocationSize(frame);lastUsed = Date.now();};@@ -210,7 +211,7 @@ export const makeKeyframeBank = ({continue;}- allocationSize -= frames[frameTimestamp].allocationSize();+ allocationSize -= getAllocationSize(frames[frameTimestamp]);frames[frameTimestamp].close();delete frames[frameTimestamp];framesDeleted++;