diff options
| author | Mel <mel@rnrd.eu> | 2025-04-17 22:51:04 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-04-17 22:51:04 +0200 |
| commit | 78d1002cbbeaac86484efadc336482c884aeec3b (patch) | |
| tree | ff0d460328011bea3cbbf89d531e909ed4fe4275 /modules | |
| parent | 353fdd896dc8d33620dc7685fb76176b872895bf (diff) | |
| download | network-78d1002cbbeaac86484efadc336482c884aeec3b.tar.zst network-78d1002cbbeaac86484efadc336482c884aeec3b.zip | |
Stream fourmi printer webcam to WebRTC
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/go2rtc.nix | 36 | ||||
| -rw-r--r-- | modules/klipper.nix | 7 |
2 files changed, 43 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"; + }; + }; + }; +} diff --git a/modules/klipper.nix b/modules/klipper.nix index 4f7be74..646969f 100644 --- a/modules/klipper.nix +++ b/modules/klipper.nix @@ -15,6 +15,8 @@ let ${../assets/printer/mainsail.cfg} \ > $out ''; + + webcamPort = 1984; in { users.users.klipper = { @@ -80,6 +82,11 @@ in forceSSL = true; listenAddresses = [ me.tailscale.ip ]; + locations."/webcam" = { + proxyPass = "http://${me.tailscale.ip}:${toString webcamPort}"; + proxyWebsockets = true; + }; + extraConfig = '' access_log /var/log/nginx/3d.access.log json_combined; ''; |
