mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Add ffmpeg input args
This commit is contained in:
parent
16b6bcca9a
commit
c017ceabf7
@ -3,6 +3,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import os
|
||||||
import signal
|
import signal
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import threading
|
import threading
|
||||||
@ -19,8 +20,9 @@ from frigate.const import (
|
|||||||
AUDIO_SAMPLE_RATE,
|
AUDIO_SAMPLE_RATE,
|
||||||
CACHE_DIR,
|
CACHE_DIR,
|
||||||
)
|
)
|
||||||
|
from frigate.ffmpeg_presets import parse_preset_input
|
||||||
from frigate.object_detection import load_labels
|
from frigate.object_detection import load_labels
|
||||||
from frigate.util import listen
|
from frigate.util import get_ffmpeg_arg_list, listen
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from tflite_runtime.interpreter import Interpreter
|
from tflite_runtime.interpreter import Interpreter
|
||||||
@ -30,7 +32,7 @@ except ModuleNotFoundError:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
FFMPEG_COMMAND = (
|
FFMPEG_COMMAND = (
|
||||||
f"ffmpeg -vn -i {{}} -f {AUDIO_FORMAT} -ar {AUDIO_SAMPLE_RATE} -ac 1 -y {{}}"
|
f"ffmpeg -vn {{}} -i {{}} -f {AUDIO_FORMAT} -ar {AUDIO_SAMPLE_RATE} -ac 1 -y {{}}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -49,10 +51,10 @@ def listen_to_audio(config: FrigateConfig, event_queue: mp.Queue) -> None:
|
|||||||
|
|
||||||
for camera in config.cameras.values():
|
for camera in config.cameras.values():
|
||||||
if camera.enabled and camera.audio.enabled:
|
if camera.enabled and camera.audio.enabled:
|
||||||
AudioEventMaintainer(camera, stop_event)
|
AudioEventMaintainer(camera, stop_event).start()
|
||||||
|
|
||||||
|
|
||||||
class AudioTfl():
|
class AudioTfl:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.labels = load_labels("/audio-labelmap.txt")
|
self.labels = load_labels("/audio-labelmap.txt")
|
||||||
self.interpreter = Interpreter(
|
self.interpreter = Interpreter(
|
||||||
@ -117,10 +119,11 @@ class AudioEventMaintainer(threading.Thread):
|
|||||||
self.shape = (int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE)),)
|
self.shape = (int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE)),)
|
||||||
self.chunk_size = int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE * 2))
|
self.chunk_size = int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE * 2))
|
||||||
self.pipe = f"{CACHE_DIR}/{self.config.name}-audio"
|
self.pipe = f"{CACHE_DIR}/{self.config.name}-audio"
|
||||||
self.ffmpeg_command = FFMPEG_COMMAND.format(
|
self.ffmpeg_command = get_ffmpeg_arg_list(FFMPEG_COMMAND.format(
|
||||||
|
" ".join(parse_preset_input(self.config.ffmpeg.input_args, 1)),
|
||||||
[i.path for i in self.config.ffmpeg.inputs if "audio" in i.roles][0],
|
[i.path for i in self.config.ffmpeg.inputs if "audio" in i.roles][0],
|
||||||
self.pipe,
|
self.pipe,
|
||||||
)
|
))
|
||||||
self.pipe_file = None
|
self.pipe_file = None
|
||||||
self.audio_listener = None
|
self.audio_listener = None
|
||||||
|
|
||||||
@ -137,10 +140,18 @@ class AudioEventMaintainer(threading.Thread):
|
|||||||
|
|
||||||
def init_ffmpeg(self) -> None:
|
def init_ffmpeg(self) -> None:
|
||||||
logger.error(f"Starting audio ffmpeg")
|
logger.error(f"Starting audio ffmpeg")
|
||||||
self.pipe_file = open(self.pipe, "rb")
|
|
||||||
|
try:
|
||||||
|
os.mkfifo(self.pipe)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
self.audio_listener = sp.run(self.ffmpeg_command)
|
self.audio_listener = sp.run(self.ffmpeg_command)
|
||||||
|
|
||||||
def read_audio(self) -> None:
|
def read_audio(self) -> None:
|
||||||
|
if self.pipe_file is None:
|
||||||
|
self.pipe_file = open(self.pipe, "rb")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
audio = self.pipe_file.read(self.chunk_size)
|
audio = self.pipe_file.read(self.chunk_size)
|
||||||
self.detect_audio(audio)
|
self.detect_audio(audio)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user