Configurable ffmpeg (#13722)

* Install multiple ffmpeg versions and add config to make it configurable

* Update docs

* Run ffprobe too

* Cleanup

* Apply config to go2rtc as well

* Fix ffmpeg bin

* Docs

* Restore path

* Cleanup env var

* Fix ffmpeg path for encoding

* Fix export

* Formatting
This commit is contained in:
Nicolas Mowen
2024-09-13 14:14:51 -06:00
committed by GitHub
parent 641f1244dd
commit 5ff476c6f9
23 changed files with 172 additions and 84 deletions

View File

@@ -314,10 +314,10 @@ class StreamInfoRetriever:
def __init__(self) -> None:
self.stream_cache: dict[str, tuple[int, int]] = {}
def get_stream_info(self, path: str) -> str:
def get_stream_info(self, ffmpeg, path: str) -> str:
if path in self.stream_cache:
return self.stream_cache[path]
info = asyncio.run(get_video_properties(path))
info = asyncio.run(get_video_properties(ffmpeg, path))
self.stream_cache[path] = info
return info

View File

@@ -765,12 +765,16 @@ def add_mask(mask: str, mask_img: np.ndarray):
def get_image_from_recording(
file_path: str, relative_frame_time: float, codec: str, height: Optional[int] = None
ffmpeg, # Ffmpeg Config
file_path: str,
relative_frame_time: float,
codec: str,
height: Optional[int] = None,
) -> Optional[any]:
"""retrieve a frame from given time in recording file."""
ffmpeg_cmd = [
"ffmpeg",
ffmpeg.executable_path,
"-hide_banner",
"-loglevel",
"warning",

View File

@@ -378,11 +378,11 @@ def get_jetson_stats() -> dict[int, dict]:
return results
def ffprobe_stream(path: str) -> sp.CompletedProcess:
def ffprobe_stream(ffmpeg, path: str) -> sp.CompletedProcess:
"""Run ffprobe on stream."""
clean_path = escape_special_characters(path)
ffprobe_cmd = [
"ffprobe",
ffmpeg.ffprobe_path,
"-timeout",
"1000000",
"-print_format",
@@ -438,7 +438,9 @@ def auto_detect_hwaccel() -> str:
return ""
async def get_video_properties(url, get_duration=False) -> dict[str, any]:
async def get_video_properties(
ffmpeg, url: str, get_duration: bool = False
) -> dict[str, any]:
async def calculate_duration(video: Optional[any]) -> float:
duration = None
@@ -453,7 +455,7 @@ async def get_video_properties(url, get_duration=False) -> dict[str, any]:
# if cv2 failed need to use ffprobe
if duration is None:
p = await asyncio.create_subprocess_exec(
"ffprobe",
ffmpeg.ffprobe_path,
"-v",
"error",
"-show_entries",