chore(motion): update settings

This commit is contained in:
arcnmx 2024-07-31 11:11:46 -07:00
parent aa6f6587a6
commit 64d302abec
6 changed files with 48 additions and 14 deletions

View file

@ -110,13 +110,11 @@ in
}; };
config.services.motion = let config.services.motion = let
configFile = pkgs.writeText "motion.conf" cfg.configText; configFile = pkgs.writeText "motion.conf" cfg.configText;
enableIPv6 = mkIf config.networking.enableIPv6 (mkOptionDefault true);
enabledCameras = filter (camera: camera.enable) (attrValues cfg.cameras); enabledCameras = filter (camera: camera.enable) (attrValues cfg.cameras);
in { in {
settings = { settings = {
target_dir = mkOptionDefault cfg.dataDir; target_dir = mkOptionDefault cfg.dataDir;
ipv6_enabled = enableIPv6; webcontrol_ipv6 = mkIf config.networking.enableIPv6 (mkOptionDefault true);
webcontrol_ipv6 = enableIPv6;
}; };
configFile = mkOptionDefault "${configFile}"; configFile = mkOptionDefault "${configFile}";
configText = mkMerge ( configText = mkMerge (

View file

@ -4,7 +4,7 @@
access, access,
... ...
}: let }: let
inherit (lib.modules) mkDefault; inherit (lib.modules) mkIf mkDefault;
inherit (lib.attrsets) mapAttrs; inherit (lib.attrsets) mapAttrs;
inherit (config.services) nginx; inherit (config.services) nginx;
system = access.systemForServiceId "kitchen"; system = access.systemForServiceId "kitchen";
@ -12,6 +12,7 @@
in { in {
config.services.nginx = { config.services.nginx = {
virtualHosts = let virtualHosts = let
# TODO: use upstreams for this!
url = access.proxyUrlFor { url = access.proxyUrlFor {
inherit system; inherit system;
service = motion; service = motion;
@ -21,6 +22,9 @@ in {
service = motion; service = motion;
portName = "stream"; portName = "stream";
}; };
mkSubFilter = port: ''
sub_filter '${port.protocol}://kitchen.local.gensokyo.zone:${toString port.port}/' '/';
'';
extraConfig = '' extraConfig = ''
proxy_redirect off; proxy_redirect off;
proxy_buffering off; proxy_buffering off;
@ -28,6 +32,11 @@ in {
locations = { locations = {
"/" = { "/" = {
proxyPass = mkDefault url; 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)$" = { "~ ^/[0-9]+/(stream|motion|substream|current|source|status\\.json)$" = {
proxyPass = mkDefault streamUrl; proxyPass = mkDefault streamUrl;
@ -42,7 +51,8 @@ in {
http = {}; http = {};
https.ssl = true; https.ssl = true;
stream = { stream = {
enable = mkDefault motion.ports.stream.enable; enable = false;
#enable = mkDefault motion.ports.stream.enable;
port = mkDefault motion.ports.stream.port; port = mkDefault motion.ports.stream.port;
}; };
}; };
@ -67,7 +77,7 @@ in {
}; };
config.networking.firewall.allowedTCPPorts = let config.networking.firewall.allowedTCPPorts = let
inherit (nginx.virtualHosts.kitchencam) listen'; inherit (nginx.virtualHosts.kitchencam) listen';
in [ in mkIf listen'.stream.enable [
listen'.stream.port listen'.stream.port
]; ];
} }

View file

@ -6,12 +6,24 @@
}: let }: let
inherit (gensokyo-zone.lib) mapDefaults; inherit (gensokyo-zone.lib) mapDefaults;
inherit (config.services) motion; inherit (config.services) motion;
format = "mjpeg"; # or "yuyv"
params = {
mjpeg = {
palette = 8;
width = 1280;
height = 720;
};
yuyv = {
palette = 15;
width = 640;
height = 480;
};
};
in { in {
services.motion.cameras.kitchencam.settings = mapDefaults { services.motion.cameras.kitchencam.settings = mapDefaults {
videodevice = "/dev/kitchencam"; video_device = "/dev/kitchencam";
video_params = "auto_brightness=2,palette=8"; # MJPG=8, YUYV=15 video_params = "auto_brightness=2,palette=${toString params.${format}.palette}";
width = 1280; inherit (params.${format}) width height;
height = 720;
framerate = 2; framerate = 2;
camera_id = 1; camera_id = 1;
text_left = "kitchen"; text_left = "kitchen";

View file

@ -2,8 +2,12 @@
inherit (gensokyo-zone.lib) mapDefaults; inherit (gensokyo-zone.lib) mapDefaults;
in { in {
services.motion.cameras.webcam.settings = mapDefaults { services.motion.cameras.webcam.settings = mapDefaults {
videodevice = "/dev/video0"; video_device = "/dev/video0";
video_params = "palette=15";
width = 1280;
height = 720;
camera_id = 3; camera_id = 3;
framerate = 3;
text_left = "logistics"; text_left = "logistics";
}; };
} }

View file

@ -8,11 +8,11 @@
inherit (config.services) motion; inherit (config.services) motion;
in { in {
services.motion.cameras.printercam.settings = mapDefaults { services.motion.cameras.printercam.settings = mapDefaults {
videodevice = "/dev/printercam"; video_device = "/dev/printercam";
video_params = "auto_brightness=1,palette=8"; # MJPG=8, YUYV=15 video_params = "auto_brightness=1,palette=8"; # MJPG=8, YUYV=15
width = 1920; width = 1920;
height = 1080; height = 1080;
framerate = 2; framerate = 4;
camera_id = 2; camera_id = 2;
text_left = ""; text_left = "";
#text_right = ""; #text_right = "";

View file

@ -18,9 +18,10 @@ in {
movie_output = false; movie_output = false;
picture_filename = "%Y%m%d%H%M%S-%q"; picture_filename = "%Y%m%d%H%M%S-%q";
movie_filename = "%t-%v-%Y%m%d%H%M%S"; movie_filename = "%t-%v-%Y%m%d%H%M%S";
movie_passthrough = true;
pause = true;
text_right = "%Y-%m-%d\\n%T-%q"; text_right = "%Y-%m-%d\\n%T-%q";
emulate_motion = false;
threshold = 1500; threshold = 1500;
despeckle_filter = "EedDl"; despeckle_filter = "EedDl";
minimum_motion_frames = 1; minimum_motion_frames = 1;
@ -33,8 +34,17 @@ in {
webcontrol_parms = 0; webcontrol_parms = 0;
webcontrol_port = webPort; webcontrol_port = webPort;
stream_port = streamPort; 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 { networking.firewall.interfaces.local = mkIf cfg.enable {
allowedTCPPorts = [cfg.settings.stream_port cfg.settings.webcontrol_port]; allowedTCPPorts = [cfg.settings.stream_port cfg.settings.webcontrol_port];
}; };