From 64d302abec1ca4bb4726f80b4d89d16690996221 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Wed, 31 Jul 2024 11:11:46 -0700 Subject: [PATCH] chore(motion): update settings --- modules/nixos/motion.nix | 4 +--- nixos/access/kitchencam.nix | 16 +++++++++++++--- nixos/cameras/kitchen.nix | 20 ++++++++++++++++---- nixos/cameras/logistics-webcam.nix | 6 +++++- nixos/cameras/printer.nix | 4 ++-- nixos/motion.nix | 12 +++++++++++- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/modules/nixos/motion.nix b/modules/nixos/motion.nix index 28832dcc..dda003ad 100644 --- a/modules/nixos/motion.nix +++ b/modules/nixos/motion.nix @@ -110,13 +110,11 @@ in }; config.services.motion = let configFile = pkgs.writeText "motion.conf" cfg.configText; - enableIPv6 = mkIf config.networking.enableIPv6 (mkOptionDefault true); enabledCameras = filter (camera: camera.enable) (attrValues cfg.cameras); in { settings = { target_dir = mkOptionDefault cfg.dataDir; - ipv6_enabled = enableIPv6; - webcontrol_ipv6 = enableIPv6; + webcontrol_ipv6 = mkIf config.networking.enableIPv6 (mkOptionDefault true); }; configFile = mkOptionDefault "${configFile}"; configText = mkMerge ( diff --git a/nixos/access/kitchencam.nix b/nixos/access/kitchencam.nix index 6c7a516f..fe38f603 100644 --- a/nixos/access/kitchencam.nix +++ b/nixos/access/kitchencam.nix @@ -4,7 +4,7 @@ access, ... }: let - inherit (lib.modules) mkDefault; + inherit (lib.modules) mkIf mkDefault; inherit (lib.attrsets) mapAttrs; inherit (config.services) nginx; system = access.systemForServiceId "kitchen"; @@ -12,6 +12,7 @@ in { config.services.nginx = { virtualHosts = let + # TODO: use upstreams for this! url = access.proxyUrlFor { inherit system; service = motion; @@ -21,6 +22,9 @@ in { service = motion; portName = "stream"; }; + mkSubFilter = port: '' + sub_filter '${port.protocol}://kitchen.local.gensokyo.zone:${toString port.port}/' '/'; + ''; extraConfig = '' proxy_redirect off; proxy_buffering off; @@ -28,6 +32,11 @@ in { locations = { "/" = { proxyPass = mkDefault url; + extraConfig = '' + sub_filter_once off; + ${mkSubFilter motion.ports.stream} + ${mkSubFilter motion.ports.default} + ''; }; "~ ^/[0-9]+/(stream|motion|substream|current|source|status\\.json)$" = { proxyPass = mkDefault streamUrl; @@ -42,7 +51,8 @@ in { http = {}; https.ssl = true; stream = { - enable = mkDefault motion.ports.stream.enable; + enable = false; + #enable = mkDefault motion.ports.stream.enable; port = mkDefault motion.ports.stream.port; }; }; @@ -67,7 +77,7 @@ in { }; config.networking.firewall.allowedTCPPorts = let inherit (nginx.virtualHosts.kitchencam) listen'; - in [ + in mkIf listen'.stream.enable [ listen'.stream.port ]; } diff --git a/nixos/cameras/kitchen.nix b/nixos/cameras/kitchen.nix index 52cd7f80..5fcf672e 100644 --- a/nixos/cameras/kitchen.nix +++ b/nixos/cameras/kitchen.nix @@ -6,12 +6,24 @@ }: let inherit (gensokyo-zone.lib) mapDefaults; inherit (config.services) motion; + format = "mjpeg"; # or "yuyv" + params = { + mjpeg = { + palette = 8; + width = 1280; + height = 720; + }; + yuyv = { + palette = 15; + width = 640; + height = 480; + }; + }; in { services.motion.cameras.kitchencam.settings = mapDefaults { - videodevice = "/dev/kitchencam"; - video_params = "auto_brightness=2,palette=8"; # MJPG=8, YUYV=15 - width = 1280; - height = 720; + video_device = "/dev/kitchencam"; + video_params = "auto_brightness=2,palette=${toString params.${format}.palette}"; + inherit (params.${format}) width height; framerate = 2; camera_id = 1; text_left = "kitchen"; diff --git a/nixos/cameras/logistics-webcam.nix b/nixos/cameras/logistics-webcam.nix index 6c711423..2f05fb9e 100644 --- a/nixos/cameras/logistics-webcam.nix +++ b/nixos/cameras/logistics-webcam.nix @@ -2,8 +2,12 @@ inherit (gensokyo-zone.lib) mapDefaults; in { services.motion.cameras.webcam.settings = mapDefaults { - videodevice = "/dev/video0"; + video_device = "/dev/video0"; + video_params = "palette=15"; + width = 1280; + height = 720; camera_id = 3; + framerate = 3; text_left = "logistics"; }; } diff --git a/nixos/cameras/printer.nix b/nixos/cameras/printer.nix index 487a4bc2..bf6b5ef2 100644 --- a/nixos/cameras/printer.nix +++ b/nixos/cameras/printer.nix @@ -8,11 +8,11 @@ inherit (config.services) motion; in { services.motion.cameras.printercam.settings = mapDefaults { - videodevice = "/dev/printercam"; + video_device = "/dev/printercam"; video_params = "auto_brightness=1,palette=8"; # MJPG=8, YUYV=15 width = 1920; height = 1080; - framerate = 2; + framerate = 4; camera_id = 2; text_left = ""; #text_right = ""; diff --git a/nixos/motion.nix b/nixos/motion.nix index 5226ee03..8e6f9e0d 100644 --- a/nixos/motion.nix +++ b/nixos/motion.nix @@ -18,9 +18,10 @@ in { movie_output = false; picture_filename = "%Y%m%d%H%M%S-%q"; movie_filename = "%t-%v-%Y%m%d%H%M%S"; + movie_passthrough = true; + pause = true; text_right = "%Y-%m-%d\\n%T-%q"; - emulate_motion = false; threshold = 1500; despeckle_filter = "EedDl"; minimum_motion_frames = 1; @@ -33,8 +34,17 @@ in { webcontrol_parms = 0; webcontrol_port = webPort; stream_port = streamPort; + + stream_maxrate = 30; + stream_quality = 75; }; }; + systemd.services.motion = mkIf cfg.enable { + serviceConfig.LogFilterPatterns = [ + ''~Corrupt image \.\.\. continue'' + ''~Invalid JPEG file structure: missing SOS marker'' + ]; + }; networking.firewall.interfaces.local = mkIf cfg.enable { allowedTCPPorts = [cfg.settings.stream_port cfg.settings.webcontrol_port]; };