blob: d24e5729d16b736ed870b69c4bc5d68a2551a80f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
{ 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
'';
};
openFirewall = mkEnableOption "open firewall";
};
config = mkIf cfg.dash.enable {
networking.firewall = mkIf cfg.dash.openFirewall {
allowedTCPPorts = [ 1935 ];
allowedUDPPorts = [ 1935 ];
};
systemd.services.brook-ffmpeg = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
StateDirectory = "dash";
Group = "nginx";
};
script = let
ffmpeg = "${pkgs.ffmpeg}/bin/ffmpeg";
in
''
while true; do
${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
done
'';
};
};
}
|