mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Get audio detection working
This commit is contained in:
parent
c017ceabf7
commit
b5acd6a287
@ -32,7 +32,7 @@ except ModuleNotFoundError:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
FFMPEG_COMMAND = (
|
||||
f"ffmpeg -vn {{}} -i {{}} -f {AUDIO_FORMAT} -ar {AUDIO_SAMPLE_RATE} -ac 1 -y {{}}"
|
||||
f"ffmpeg {{}} -i {{}} -f {AUDIO_FORMAT} -ar {AUDIO_SAMPLE_RATE} -ac 1 -y {{}}"
|
||||
)
|
||||
|
||||
|
||||
@ -119,11 +119,16 @@ class AudioEventMaintainer(threading.Thread):
|
||||
self.shape = (int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE)),)
|
||||
self.chunk_size = int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE * 2))
|
||||
self.pipe = f"{CACHE_DIR}/{self.config.name}-audio"
|
||||
self.ffmpeg_command = get_ffmpeg_arg_list(FFMPEG_COMMAND.format(
|
||||
" ".join(parse_preset_input(self.config.ffmpeg.input_args, 1)),
|
||||
self.ffmpeg_cmd = get_ffmpeg_arg_list(
|
||||
FFMPEG_COMMAND.format(
|
||||
" ".join(
|
||||
self.config.ffmpeg.global_args
|
||||
+ parse_preset_input("preset-rtsp-audio-only", 1)
|
||||
),
|
||||
[i.path for i in self.config.ffmpeg.inputs if "audio" in i.roles][0],
|
||||
self.pipe,
|
||||
))
|
||||
)
|
||||
)
|
||||
self.pipe_file = None
|
||||
self.audio_listener = None
|
||||
|
||||
@ -139,21 +144,27 @@ class AudioEventMaintainer(threading.Thread):
|
||||
# TODO handle valid detect
|
||||
|
||||
def init_ffmpeg(self) -> None:
|
||||
logger.error(f"Starting audio ffmpeg")
|
||||
|
||||
try:
|
||||
os.mkfifo(self.pipe)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
self.audio_listener = sp.run(self.ffmpeg_command)
|
||||
logger.error(f"Made the pipe")
|
||||
|
||||
self.audio_listener = sp.Popen(
|
||||
self.ffmpeg_cmd,
|
||||
stdout=sp.DEVNULL,
|
||||
stdin=sp.DEVNULL,
|
||||
start_new_session=True,
|
||||
)
|
||||
logger.error(f"Started ffmpeg")
|
||||
|
||||
def read_audio(self) -> None:
|
||||
if self.pipe_file is None:
|
||||
self.pipe_file = open(self.pipe, "rb")
|
||||
|
||||
try:
|
||||
audio = self.pipe_file.read(self.chunk_size)
|
||||
audio = np.frombuffer(self.pipe_file.read(self.chunk_size), dtype=np.int16)
|
||||
self.detect_audio(audio)
|
||||
except BrokenPipeError as e:
|
||||
logger.error(f"There was a broken pipe :: {e}")
|
||||
|
||||
@ -282,6 +282,13 @@ PRESETS_INPUT = {
|
||||
"-use_wallclock_as_timestamps",
|
||||
"1",
|
||||
],
|
||||
"preset-rtsp-audio-only": [
|
||||
"-rtsp_transport",
|
||||
"tcp",
|
||||
TIMEOUT_PARAM,
|
||||
"5000000",
|
||||
"-vn",
|
||||
],
|
||||
"preset-rtsp-restream": _user_agent_args
|
||||
+ [
|
||||
"-rtsp_transport",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user