27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.shouldUseParallelEncoding = void 0;
|
|
const get_available_memory_1 = require("./memory/get-available-memory");
|
|
const estimateMemoryUsageForPrestitcher = ({ width, height, }) => {
|
|
// Empirically we detected that per 1 million pixels, FFMPEG uses around 1GB of memory, relatively independent of
|
|
// the duration of the video.
|
|
const memoryUsageFor4K = 1000000000;
|
|
const memoryUsageOfPixel = memoryUsageFor4K / 1000000;
|
|
return memoryUsageOfPixel * width * height;
|
|
};
|
|
const shouldUseParallelEncoding = ({ width, height, logLevel, }) => {
|
|
const freeMemory = (0, get_available_memory_1.getAvailableMemory)(logLevel);
|
|
const estimatedUsage = estimateMemoryUsageForPrestitcher({
|
|
height,
|
|
width,
|
|
});
|
|
const hasEnoughMemory = freeMemory - estimatedUsage > 2000000000 &&
|
|
estimatedUsage / freeMemory < 0.5;
|
|
return {
|
|
hasEnoughMemory,
|
|
freeMemory,
|
|
estimatedUsage,
|
|
};
|
|
};
|
|
exports.shouldUseParallelEncoding = shouldUseParallelEncoding;
|