import React, { useState, useEffect } from "react"; import Admonition from "@theme/Admonition"; import styles from "./styles.module.css"; // follows calculate_shm_requirements() in frigate/util/services.py, but sizes // for 25 frames so float rounding can't land under its 20 frame warning const MB = 1048576; const RESERVED_MB = 50; // logs + nginx cache const TARGET_FRAMES = 25; const DEFAULT_FRAMES = 50; const frameMb = (width, height) => Math.round(((width * height * 1.5 + 270480) / MB) * 10) / 10; // room for 2 cameras added at runtime, sized as 720p const addedCamerasMb = 2 * frameMb(1280, 720); const ShmCalculator = () => { const [width, setWidth] = useState(1280); const [height, setHeight] = useState(720); const [cameraCount, setCameraCount] = useState(1); const [result, setResult] = useState("-"); const [singleCameraShm, setSingleCameraShm] = useState("-"); const [addedCamerasShm, setAddedCamerasShm] = useState("-"); const [fullRingShm, setFullRingShm] = useState("-"); const calculate = () => { if (!width || !height || !cameraCount) { setResult("Please enter valid values"); setSingleCameraShm("-"); setAddedCamerasShm("-"); setFullRingShm("-"); return; } const cameraFramesMb = cameraCount * frameMb(width, height) + addedCamerasMb; setSingleCameraShm(formatMb(frameMb(width, height) * TARGET_FRAMES)); setAddedCamerasShm(formatMb(addedCamerasMb * TARGET_FRAMES)); setResult(formatMb(Math.round(RESERVED_MB + cameraFramesMb * TARGET_FRAMES))); setFullRingShm( formatMb(Math.round(RESERVED_MB + cameraFramesMb * DEFAULT_FRAMES)), ); }; const formatMb = (value) => { if (value >= 1024) { return `${(value / 1024).toFixed(2)}gb`; } return `${Number(value.toFixed(2))}mb`; }; const formatWithUnit = (value) => { const match = value.match(/^([\d.]+)(mb|kb|gb)$/i); if (match) { return ( <> {match[1]}{match[2]} > ); } return value; }; const applyPreset = (w, h, count) => { setWidth(w); setHeight(h); setCameraCount(count); calculate(); }; useEffect(() => { calculate(); }, [width, height, cameraCount]); return (
Calculate required shared memory (SHM) based on camera resolution and count
Per Camera: {formatWithUnit(singleCameraShm)}
Formula: (width × height × 1.5 + 270480) ÷ 1048576 × {TARGET_FRAMES} frames
Room for 2 Added Cameras:{" "} {formatWithUnit(addedCamerasShm)}
Logs and Cache: + {RESERVED_MB} mb
Birdseye Restream: + 8 mb if enabled
For {DEFAULT_FRAMES} Frames:{" "} {formatWithUnit(fullRingShm)}