Cache camera stream info to speed up future config generations (#11614)

* Cache camera stream info to speed up future config generations

* Formatting

* fix
This commit is contained in:
Nicolas Mowen
2024-05-29 07:41:41 -06:00
committed by GitHub
parent cf4517cbdb
commit d5f6decd30
2 changed files with 21 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
"""configuration utils."""
import asyncio
import logging
import os
import shutil
@@ -8,6 +9,7 @@ from typing import Optional, Union
from ruamel.yaml import YAML
from frigate.const import CONFIG_DIR, EXPORT_DIR
from frigate.util.services import get_video_properties
logger = logging.getLogger(__name__)
@@ -194,3 +196,16 @@ def get_relative_coordinates(
return mask
return mask
class StreamInfoRetriever:
def __init__(self) -> None:
self.stream_cache: dict[str, tuple[int, int]] = {}
def get_stream_info(self, path: str) -> str:
if path in self.stream_cache:
return self.stream_cache[path]
info = asyncio.run(get_video_properties(path))
self.stream_cache[path] = info
return info