From 99577a57e6a74ed757b811735702d278e04f6812 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sun, 15 Jan 2023 08:40:42 -0700 Subject: [PATCH] Add specific presets for restream and record with audio (#5094) * Add more ffmpeg presets * Update docs * Update tests * Update docs to optimize setup --- docs/docs/configuration/ffmpeg_presets.md | 34 ++++++++++++----------- docs/docs/configuration/restream.md | 10 +++++-- frigate/ffmpeg_presets.py | 23 ++++++++++++++- frigate/test/test_ffmpeg_presets.py | 4 +-- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/docs/docs/configuration/ffmpeg_presets.md b/docs/docs/configuration/ffmpeg_presets.md index bde76b9b4..36df0f50d 100644 --- a/docs/docs/configuration/ffmpeg_presets.md +++ b/docs/docs/configuration/ffmpeg_presets.md @@ -28,15 +28,16 @@ Input args presets help make the config more readable and handle use cases for d See [the camera specific docs](/configuration/camera_specific.md) for more info on non-standard cameras and recommendations for using them in Frigate. -| Preset | Usage | Other Notes | -| ------------------------- | ----------------------- | --------------------------------------------------- | -| preset-http-jpeg-generic | HTTP Live Jpeg | Recommend restreaming live jpeg instead | -| preset-http-mjpeg-generic | HTTP Mjpeg Stream | Recommend restreaming mjpeg stream instead | -| preset-http-reolink | Reolink HTTP-FLV Stream | Only for reolink http, not when restreaming as rtsp | -| preset-rtmp-generic | RTMP Stream | | -| preset-rtsp-generic | RTSP Stream | This is the default when nothing is specified | -| preset-rtsp-udp | RTSP Stream via UDP | Use when camera is UDP only | -| preset-rtsp-blue-iris | Blue Iris RTSP Stream | Use when consuming a stream from Blue Iris | +| Preset | Usage | Other Notes | +| ------------------------- | ------------------------- | --------------------------------------------------- | +| preset-http-jpeg-generic | HTTP Live Jpeg | Recommend restreaming live jpeg instead | +| preset-http-mjpeg-generic | HTTP Mjpeg Stream | Recommend restreaming mjpeg stream instead | +| preset-http-reolink | Reolink HTTP-FLV Stream | Only for reolink http, not when restreaming as rtsp | +| preset-rtmp-generic | RTMP Stream | | +| preset-rtsp-generic | RTSP Stream | This is the default when nothing is specified | +| preset-rtsp-restream | RTSP Stream from restream | Use when using rtsp restream as source | +| preset-rtsp-udp | RTSP Stream via UDP | Use when camera is UDP only | +| preset-rtsp-blue-iris | Blue Iris RTSP Stream | Use when consuming a stream from Blue Iris | :::caution @@ -66,10 +67,11 @@ cameras: Output args presets help make the config more readable and handle use cases for different types of streams to ensure consistent recordings. -| Preset | Usage | Other Notes | -| --------------------------- | --------------------------------- | --------------------------------------------- | -| preset-record-generic | Record WITHOUT audio | This is the default when nothing is specified | -| preset-record-generic-audio | Record WITH audio | Use this to enable audio in recordings | -| preset-record-mjpeg | Record an mjpeg stream | Recommend restreaming mjpeg stream instead | -| preset-record-jpeg | Record live jpeg | Recommend restreaming live jpeg instead | -| preset-record-ubiquiti | Record ubiquiti stream with audio | Recordings with ubiquiti non-standard audio | +| Preset | Usage | Other Notes | +| -------------------------------- | --------------------------------- | --------------------------------------------- | +| preset-record-generic | Record WITHOUT audio | This is the default when nothing is specified | +| preset-record-generic-audio-aac | Record WITH aac audio | Use this to enable audio in recordings | +| preset-record-generic-audio-copy | Record WITH original audio | Use this to enable audio in recordings | +| preset-record-mjpeg | Record an mjpeg stream | Recommend restreaming mjpeg stream instead | +| preset-record-jpeg | Record live jpeg | Recommend restreaming live jpeg instead | +| preset-record-ubiquiti | Record ubiquiti stream with audio | Recordings with ubiquiti non-standard audio | diff --git a/docs/docs/configuration/restream.md b/docs/docs/configuration/restream.md index 8cea0e019..845baed8e 100644 --- a/docs/docs/configuration/restream.md +++ b/docs/docs/configuration/restream.md @@ -47,8 +47,11 @@ One connection is made to the camera. One for the restream, `detect` and `record cameras: test_cam: ffmpeg: + output_args: + record: preset-record-audio-copy inputs: - - path: rtsp://127.0.0.1:8554/test_cam # <--- the name here must match the name of the camera + - path: rtsp://127.0.0.1:8554/test_cam?video=copy&audio=aac # <--- the name here must match the name of the camera + input_args: preset-rtsp-restream roles: - record - detect @@ -65,8 +68,11 @@ Two connections are made to the camera. One for the sub stream, one for the rest cameras: test_cam: ffmpeg: + output_args: + record: preset-record-audio-copy inputs: - - path: rtsp://127.0.0.1:8554/test_cam # <--- the name here must match the name of the camera + - path: rtsp://127.0.0.1:8554/test_cam?video=copy&audio=aac # <--- the name here must match the name of the camera + input_args: preset-rtsp-restream roles: - record - path: rtsp://192.168.1.5:554/stream # <--- camera high res stream diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index e0694f9e7..650b2fdf6 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -247,6 +247,13 @@ PRESETS_INPUT = { "-use_wallclock_as_timestamps", "1", ], + "preset-rtsp-restream": _user_agent_args + + [ + "-rtsp_transport", + "tcp", + TIMEOUT_PARAM, + "5000000", + ], "preset-rtsp-udp": _user_agent_args + [ "-avoid_negative_ts", @@ -311,7 +318,7 @@ PRESETS_RECORD_OUTPUT = { "copy", "-an", ], - "preset-record-generic-audio": [ + "preset-record-generic-audio-aac": [ "-f", "segment", "-segment_time", @@ -327,6 +334,20 @@ PRESETS_RECORD_OUTPUT = { "-c:a", "aac", ], + "preset-record-generic-audio-copy": [ + "-f", + "segment", + "-segment_time", + "10", + "-segment_format", + "mp4", + "-reset_timestamps", + "1", + "-strftime", + "1", + "-c", + "copy", + ], "preset-record-mjpeg": [ "-f", "segment", diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py index 7e3f68195..6ea623790 100644 --- a/frigate/test/test_ffmpeg_presets.py +++ b/frigate/test/test_ffmpeg_presets.py @@ -136,10 +136,10 @@ class TestFfmpegPresets(unittest.TestCase): def test_ffmpeg_output_record_preset(self): self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["output_args"][ "record" - ] = "preset-record-generic-audio" + ] = "preset-record-generic-audio-aac" frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() - assert "preset-record-generic-audio" not in ( + assert "preset-record-generic-audio-aac" not in ( " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) ) assert "-c:v copy -c:a aac" in (