Commit aed440ba authored by Samuel Laurén's avatar Samuel Laurén
Browse files

Refactor

parent 12225fd4
......@@ -71,6 +71,7 @@
services.coffeecam = {
enable = true;
user = "coffeecam";
targetAddress = "rtp://130.232.103.36:2222";
device = "/dev/v4l/by-id/usb-Generic_USB2.0_PC_CAMERA-video-index0";
};
......
......@@ -5,62 +5,68 @@ with lib;
let cfg = config.services.coffeecam;
in {
options.services.coffeecam = {
enable = mkEnableOption "coffeecam";
options = {
services.coffeecam = {
enable = mkEnableOption "coffeecam";
targetAddress = mkOption {
description = "Stream target";
type = types.str;
example = "rtp://example.com:2222";
};
targetAddress = mkOption {
description = "Stream target";
type = types.str;
example = "rtp://example.com:2222";
};
device = mkOption {
description = "Input device";
type = types.path;
default = "/dev/video0";
};
device = mkOption {
description = "Input device";
type = types.path;
default = "/dev/video0";
};
imagePath = mkOption {
description = "Output image path";
type = types.path;
default = "/dev/shm/coffeecam-static.jpg";
imagePath = mkOption {
description = "Output image path";
type = types.path;
default = "/dev/shm/coffeecam-static.jpg";
};
user = mkOption {
description = "Username";
type = types.str;
};
};
};
# Are these options in any way sensible
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.ffmpeg pkgs.dejavu_fonts ];
systemd.services.coffeecam = {
description = "CoffeeCam transmission";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
User = "coffeecam";
Group = "users";
ExecStart = lib.replaceStrings ["\n"] [" "] ''
${pkgs.ffmpeg}/bin/ffmpeg
-y
-r 15
-s 640x480
-f video4linux2
-i ${cfg.device}
-pix_fmt yuv420p
-vcodec mpeg4
-r 15
-f rtp_mpegts
-vf 'hflip,drawtext=fontsize=15:fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:rate=1/2:text=%{localtime}:fontsize=11:fontcolor='white':boxcolor=0x00000099:box=1:x=320-text_w/2:y=480-text_h'
-threads 2
-r 15 ${cfg.targetAddress}
-r 15
-f image2
-r 1/5
-qscale:v 4
-updatefirst 1
-vf 'hflip'
${cfg.imagePath}
'';
Restart = "on-failure";
};
# Are these options in any way sensible
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.ffmpeg pkgs.dejavu_fonts ];
systemd.services.coffeecam = {
description = "CoffeeCam transmission";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
User = "${cfg.user}";
ExecStart = lib.replaceStrings ["\n"] [" "] ''
${pkgs.ffmpeg}/bin/ffmpeg
-y
-r 15
-s 640x480
-f video4linux2
-i ${cfg.device}
-pix_fmt yuv420p
-vcodec mpeg4
-r 15
-f rtp_mpegts
-vf 'hflip,drawtext=fontsize=15:fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:rate=1/2:text=%{localtime}:fontsize=11:fontcolor='white':boxcolor=0x00000099:box=1:x=320-text_w/2:y=480-text_h'
-threads 2
-r 15 ${cfg.targetAddress}
-r 15
-f image2
-r 1/5
-qscale:v 4
-updatefirst 1
-vf 'hflip'
${cfg.imagePath}
'';
Restart = "on-failure";
};
};
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment