From 857e0584d19e0abbc9f73a7ea9aea24be6a6786e Mon Sep 17 00:00:00 2001 From: hyperion Date: Fri, 30 Oct 2020 12:00:11 +0100 Subject: Refactoring repository structure and building basic nix module --- nix/dash.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 nix/dash.nix (limited to 'nix/dash.nix') diff --git a/nix/dash.nix b/nix/dash.nix new file mode 100644 index 0000000..c0af4d7 --- /dev/null +++ b/nix/dash.nix @@ -0,0 +1,44 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + cfg = config.services.brook; +in +{ + options.services.brook.dash = { + enable = mkEnableOption "ffmpeg dash server"; + + name = mkOption { + type = types.str; + description = '' + The name of the rtmp endpoint of the stream. This might show up as + metadata in some clients + ''; + }; + }; + + config = mkIf cfg.dash.enable { + systemd.services.brook-ffmpeg = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + StateDirectory = "dash"; + Group = "nginx"; + }; + + script = let + ffmpeg = "${pkgs.ffmpeg}/bin/ffmpeg"; + in + '' + ${ffmpeg}-listen 1 -i rtmp://0.0.0.0:1935/${cfg.dash.name}/live \ + -c:v libx264 -x264opts "keyint=24:min-keyint=24:no-scenecut" -r 24 \ + -c:a aac -b:a 128k \ + -bf 1 -b_strategy 0 -sc_threshold 0 -pix_fmt yuv420p \ + -map 0:v:0 -map 0:a:0 -map 0:v:0 \ + -map 0:a:0 -map 0:v:0 -map 0:a:0 \ + /var/lib/dash/live.mpd + ''; + }; + }; +} -- cgit v1.2.3