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

Made ffmpeg streamer into its own module. Haven't tested these changes, lets...

Made ffmpeg streamer into its own module. Haven't tested these changes, lets hope they are not too broken.
parent ee57dbb1
{ config, pkgs, lib, ... }:
{
nix.maxJobs = lib.mkDefault 2;
imports = [
"./services/coffeecam.nix"
];
nix = {
useSandbox = true;
buildCores = 0;
}
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
......@@ -36,8 +43,6 @@
environment.systemPackages = with pkgs; [
git
ffmpeg
dejavu_fonts
];
programs.bash.enableCompletion = true;
......@@ -58,34 +63,10 @@
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAe0DzM/LknI0iCLYukQNOr4auToVmePbIHYkHm8BupC"
];
systemd.user.services.coffeecam = {
description = "CoffeeCam transmission";
serviceConfig = {
ExecStart = lib.replaceStrings ["\n"] [" "] ''
${pkgs.ffmpeg}/bin/ffmpeg
-y
-r 15
-s 640x480
-f video4linux2
-i /dev/v4l/by-id/usb-Generic_USB2.0_PC_CAMERA-video-index0
-pix_fmt yuv420p
-vcodec mpeg4
-r 15
-f rtp_mpegts
-vf 'hflip,rotate=PI/2/180*70,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 rtp://130.232.103.36:2222
-r 15
-f image2
-r 1/5
-qscale:v 4
-updatefirst 1
-vf "hflip,rotate=PI/2/180*70"
/dev/shm/img.jpg
'';
Restart = "on-failure";
};
wantedBy = [ "default.target" ];
services.coffeecam = {
enable = true;
targetAddress = "rtp://130.232.103.36:2222";
device = "/dev/v4l/by-id/usb-Generic_USB2.0_PC_CAMERA-video-index0";
};
system.stateVersion = "17.09";
......
{ config, lib, pkgs, ... }:
with lib;
let cfg = config.services.coffeecam;
in {
options.services.coffeecam = {
enable = mkOption {
description = "Enable coffeecam streaming service";
type = types.bool;
default = false;
};
targetAddress = mkOption {
description = "Stream target";
type = types.str;
example = "rtp://example.com:2222";
}
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";
}
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.ffmpeg pkgs.dejavu_fonts ];
systemd.user.services.coffeecam = {
description = "CoffeeCam transmission";
wantedBy = [ "default.target" ];
after = [ "network.target" ];
serviceConfig = {
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
${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