huge refactor
This commit is contained in:
parent
03e5a47910
commit
1d4c8455ee
30 changed files with 972 additions and 697 deletions
|
|
@ -100,6 +100,21 @@ in
|
|||
default = 24;
|
||||
description = "VAAPI quality parameter (lower means better quality, higher CPU/bitrate).";
|
||||
};
|
||||
waitForRtsp = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Wait for the RTSP destination to accept TCP connections before ffmpeg starts.";
|
||||
};
|
||||
waitForRtspTimeoutSec = mkOption {
|
||||
type = types.int;
|
||||
default = 30;
|
||||
description = "Maximum seconds to wait for RTSP destination availability.";
|
||||
};
|
||||
waitForRtspIntervalSec = mkOption {
|
||||
type = types.int;
|
||||
default = 1;
|
||||
description = "Seconds between RTSP availability checks.";
|
||||
};
|
||||
vaapiDriver = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
|
|
@ -209,6 +224,13 @@ in
|
|||
"-rc_mode VBR -b:v ${toString streamCfg.bitrateKbps}k -maxrate ${toString maxrateKbps}k -bufsize ${toString bufsizeKbps}k"
|
||||
else
|
||||
"-rc_mode CQP -qp ${toString streamCfg.vaapiQp}";
|
||||
rtspUrlMatch = builtins.match "rtsp://([^/:]+)(:([0-9]+))?/.*" streamCfg.rtspUrl;
|
||||
rtspHost = if rtspUrlMatch != null then builtins.elemAt rtspUrlMatch 0 else "127.0.0.1";
|
||||
rtspPort =
|
||||
if rtspUrlMatch != null && builtins.elemAt rtspUrlMatch 2 != null then
|
||||
builtins.elemAt rtspUrlMatch 2
|
||||
else
|
||||
"8554";
|
||||
videoCodecArgs =
|
||||
if streamCfg.useVaapi then
|
||||
"-vaapi_device ${streamCfg.vaapiDevice} -vf format=nv12,hwupload -c:v h264_vaapi -profile:v main -level:v 4.1 ${vaapiRateControlArgs} -g ${
|
||||
|
|
@ -230,6 +252,22 @@ in
|
|||
Restart = "always";
|
||||
RestartSec = "2";
|
||||
Environment = optional (streamCfg.vaapiDriver != null) "LIBVA_DRIVER_NAME=${streamCfg.vaapiDriver}";
|
||||
ExecStartPre = optional cfg.waitForRtsp (
|
||||
pkgs.writeShellScript "wait-for-rtsp-${sanitizeName streamName}" ''
|
||||
set -eu
|
||||
retries=${toString cfg.waitForRtspTimeoutSec}
|
||||
interval=${toString cfg.waitForRtspIntervalSec}
|
||||
i=0
|
||||
until ${pkgs.netcat-openbsd}/bin/nc -z -w1 ${rtspHost} ${rtspPort}; do
|
||||
i=$((i + 1))
|
||||
if [ "$i" -ge "$retries" ]; then
|
||||
echo "Timed out waiting for RTSP server at ${rtspHost}:${rtspPort}" >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep "$interval"
|
||||
done
|
||||
''
|
||||
);
|
||||
ExecStart = "${pkgs.ffmpeg}/bin/ffmpeg -hide_banner -loglevel warning -f v4l2 -framerate ${toString streamCfg.framerate} -video_size ${streamCfg.videoSize} -i ${streamCfg.device} ${videoCodecArgs} -f rtsp -rtsp_transport tcp ${streamCfg.rtspUrl}";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue