mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 09:45:22 +03:00
Make util to clean up redundant code
This commit is contained in:
parent
028cd999b7
commit
c6160181bb
@ -21,11 +21,15 @@ from frigate.const import (
|
|||||||
from frigate.util import (
|
from frigate.util import (
|
||||||
create_mask,
|
create_mask,
|
||||||
deep_merge,
|
deep_merge,
|
||||||
|
get_ffmpeg_arg_list,
|
||||||
escape_special_characters,
|
escape_special_characters,
|
||||||
load_config_with_no_duplicates,
|
load_config_with_no_duplicates,
|
||||||
load_labels,
|
load_labels,
|
||||||
)
|
)
|
||||||
from frigate.ffmpeg_presets import parse_preset_hardware_acceleration, parse_preset_input
|
from frigate.ffmpeg_presets import (
|
||||||
|
parse_preset_hardware_acceleration,
|
||||||
|
parse_preset_input,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -647,11 +651,8 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
def _get_ffmpeg_cmd(self, ffmpeg_input: CameraInput):
|
def _get_ffmpeg_cmd(self, ffmpeg_input: CameraInput):
|
||||||
ffmpeg_output_args = []
|
ffmpeg_output_args = []
|
||||||
if "detect" in ffmpeg_input.roles:
|
if "detect" in ffmpeg_input.roles:
|
||||||
detect_args = (
|
detect_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.detect)
|
||||||
self.ffmpeg.output_args.detect
|
|
||||||
if isinstance(self.ffmpeg.output_args.detect, list)
|
|
||||||
else self.ffmpeg.output_args.detect.split(" ")
|
|
||||||
)
|
|
||||||
ffmpeg_output_args = (
|
ffmpeg_output_args = (
|
||||||
[
|
[
|
||||||
"-r",
|
"-r",
|
||||||
@ -664,20 +665,13 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
+ ["pipe:"]
|
+ ["pipe:"]
|
||||||
)
|
)
|
||||||
if "rtmp" in ffmpeg_input.roles and self.rtmp.enabled:
|
if "rtmp" in ffmpeg_input.roles and self.rtmp.enabled:
|
||||||
rtmp_args = (
|
rtmp_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.rtmp)
|
||||||
self.ffmpeg.output_args.rtmp
|
|
||||||
if isinstance(self.ffmpeg.output_args.rtmp, list)
|
|
||||||
else self.ffmpeg.output_args.rtmp.split(" ")
|
|
||||||
)
|
|
||||||
ffmpeg_output_args = (
|
ffmpeg_output_args = (
|
||||||
rtmp_args + [f"rtmp://127.0.0.1/live/{self.name}"] + ffmpeg_output_args
|
rtmp_args + [f"rtmp://127.0.0.1/live/{self.name}"] + ffmpeg_output_args
|
||||||
)
|
)
|
||||||
if "record" in ffmpeg_input.roles and self.record.enabled:
|
if "record" in ffmpeg_input.roles and self.record.enabled:
|
||||||
record_args = (
|
record_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.record)
|
||||||
self.ffmpeg.output_args.record
|
|
||||||
if isinstance(self.ffmpeg.output_args.record, list)
|
|
||||||
else self.ffmpeg.output_args.record.split(" ")
|
|
||||||
)
|
|
||||||
|
|
||||||
ffmpeg_output_args = (
|
ffmpeg_output_args = (
|
||||||
record_args
|
record_args
|
||||||
@ -689,18 +683,18 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
if len(ffmpeg_output_args) == 0:
|
if len(ffmpeg_output_args) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
global_args = ffmpeg_input.global_args or self.ffmpeg.global_args
|
global_args = get_ffmpeg_arg_list(
|
||||||
hwaccel_args = ffmpeg_input.hwaccel_args or parse_preset_hardware_acceleration(self.ffmpeg.hwaccel_args) or self.ffmpeg.hwaccel_args
|
ffmpeg_input.global_args or self.ffmpeg.global_args
|
||||||
input_args = ffmpeg_input.input_args or parse_preset_input(self.ffmpeg.input_args, self.detect.fps) or self.ffmpeg.input_args
|
|
||||||
|
|
||||||
global_args = (
|
|
||||||
global_args if isinstance(global_args, list) else global_args.split(" ")
|
|
||||||
)
|
)
|
||||||
hwaccel_args = (
|
hwaccel_args = get_ffmpeg_arg_list(
|
||||||
hwaccel_args if isinstance(hwaccel_args, list) else hwaccel_args.split(" ")
|
ffmpeg_input.hwaccel_args
|
||||||
|
or parse_preset_hardware_acceleration(self.ffmpeg.hwaccel_args)
|
||||||
|
or self.ffmpeg.hwaccel_args
|
||||||
)
|
)
|
||||||
input_args = (
|
input_args = get_ffmpeg_arg_list(
|
||||||
input_args if isinstance(input_args, list) else input_args.split(" ")
|
ffmpeg_input.input_args
|
||||||
|
or parse_preset_input(self.ffmpeg.input_args, self.detect.fps)
|
||||||
|
or self.ffmpeg.input_args
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd = (
|
cmd = (
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from abc import ABC, abstractmethod
|
|||||||
from collections import Counter
|
from collections import Counter
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from multiprocessing import shared_memory
|
from multiprocessing import shared_memory
|
||||||
from typing import AnyStr
|
from typing import Any, AnyStr
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -886,6 +886,11 @@ def vainfo_hwaccel() -> sp.CompletedProcess:
|
|||||||
return sp.run(ffprobe_cmd, capture_output=True)
|
return sp.run(ffprobe_cmd, capture_output=True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_ffmpeg_arg_list(arg: Any) -> list:
|
||||||
|
"""Use arg if list or convert to list format."""
|
||||||
|
return (arg if isinstance(arg, list) else arg.split(" "))
|
||||||
|
|
||||||
|
|
||||||
class FrameManager(ABC):
|
class FrameManager(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def create(self, name, size) -> AnyStr:
|
def create(self, name, size) -> AnyStr:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user