summary refs log tree commit diff
path: root/modules/go2rtc.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/go2rtc.nix')
-rw-r--r--modules/go2rtc.nix36
1 files changed, 36 insertions, 0 deletions
diff --git a/modules/go2rtc.nix b/modules/go2rtc.nix
new file mode 100644
index 0000000..7ee7ae3
--- /dev/null
+++ b/modules/go2rtc.nix
@@ -0,0 +1,36 @@
+{ me, ... }:
+
+let
+  ffmpegDevice =
+    device: format: resolution: hz:
+    "ffmpeg:device?video=${device}&input_format=${format}&video_size=${resolution}&framerate=${hz}#video=h264#hardware";
+
+  go2rtcPort = 1984;
+  webrtcPort = 8555;
+in
+{
+  services.go2rtc = {
+    enable = true;
+
+    settings = {
+      api = {
+        listen = "${me.tailscale.ip}:${toString go2rtcPort}";
+        base_path = "/webcam";
+        origin = "*"; # stop cors annoyance!
+      };
+
+      webrtc =
+        let
+          address = "${me.tailscale.ip}:${toString webrtcPort}";
+        in
+        {
+          listen = address;
+          candidates = [ address ];
+        };
+
+      streams = {
+        webcam = ffmpegDevice "/dev/video0" "yuyv422" "1280x720" "30";
+      };
+    };
+  };
+}