diff --git a/nixos/components/media/default.nix b/nixos/components/media/default.nix index 5de2f67..95681a1 100644 --- a/nixos/components/media/default.nix +++ b/nixos/components/media/default.nix @@ -8,6 +8,7 @@ with lib; imports = [ ./icecast.nix ./tts.nix + ./video.nix ]; config = mkIf config.components.media.enable { }; diff --git a/nixos/components/media/sanitize_folder.sh b/nixos/components/media/sanitize_folder.sh new file mode 100644 index 0000000..0e75166 --- /dev/null +++ b/nixos/components/media/sanitize_folder.sh @@ -0,0 +1,20 @@ +#! /bin/bash + +# todo : add a dry-run + +sanitize() { + shopt -s extglob; + + filename=$(basename "$1") + directory=$(dirname "$1") + + filename_clean="${filename//+([^[:alnum:]_-\\.])/_}" + + if (test "$filename" != "$filename_clean") + then + mv -v --backup=numbered "$1" "$directory/$filename_clean" + fi +} + +export -f sanitize +find $1 -depth -exec bash -c 'sanitize "$0"' {} \; diff --git a/nixos/components/media/video.nix b/nixos/components/media/video.nix new file mode 100644 index 0000000..b9794de --- /dev/null +++ b/nixos/components/media/video.nix @@ -0,0 +1,119 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + + # Lassulus streaming setup + # ------------------------- + # ffmpeg \ + # -f pulse \ + # -i default \ + # -vaapi_device /dev/dri/renderD128 \ + # -f x11grab \ + # -video_size 1366x768 \ + # -i :0 \ + # -vf 'hwupload,scale_vaapi=format=nv12' \ + # -c:v h264_vaapi \ + # -c:a aac \ + # -b:a 96k \ + # -af "highpass=f=200, lowpass=f=3000" \ + # -qp 30 \ + # -f flv \ + # rtmp://lassul.us:1935/stream/nixos \ + # ./rc3-output-$(date +%d%H%M%S).mp4 + # + # Dann abspielen mit : + # mpv rtmp://lassul.us:1935/stream/nixos + + # show keyboard input on desktop for screencasts + screenKey = pkgs.symlinkJoin { + name = "screen-keys"; + paths = + let + screenKeyScript = { position ? "bottom", size ? "small", ... }: + pkgs.writeShellScriptBin "screenkeys-${position}-${size}" # sh + '' + ${pkgs.screenkey}/bin/screenkey \ + --no-detach \ + --bg-color '#fdf6e3' \ + --font-color '#073642' \ + -p ${position} \ + -s ${size} \ + "$@" + ''; + in + lib.flatten (lib.flip map [ "large" "small" "medium" ] (size: + lib.flip map [ "top" "center" "bottom" ] + (position: screenKeyScript { inherit size position; }))); + }; + + + mpvReview = + let + moveToDir = key: dir: pkgs.writeText "move-with-${key}.lua" '' + tmp_dir = "${dir}" + + function move_current_track_${key}() + track = mp.get_property("path") + os.execute("mkdir -p '" .. tmp_dir .. "'") + os.execute("mv '" .. track .. "' '" .. tmp_dir .. "'") + print("moved '" .. track .. "' to " .. tmp_dir) + mp.command("playlist-next") + end + + mp.add_key_binding("${key}", "move_current_track_${key}", move_current_track_${key}) + ''; + delete = moveToDir "D" "./.graveyard"; + good = moveToDir "G" "./.good"; + in + pkgs.writers.writeDashBin "mpv-review" '' + exec ${pkgs.mpv}/bin/mpv --no-config --script=${delete} --script=${good} "$@" + ''; + + alphaSafe = pkgs.writers.writeBashBin "alpha-safe" '' + export PATH=${pkgs.gnused}/bin:$PATH + echo "$1" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/--/-/g' | sed 's/-$//g' + ''; + + sanitizeFolder = pkgs.writers.writeBashBin "sanitize-folder" (fileContents ./sanitize_folder.sh); + +in +{ + + options.components.media.video.enable = mkOption { + type = lib.types.bool; + default = config.components.media.enable; + }; + + config = mkIf (config.components.media.video.enable) { + + environment.systemPackages = with pkgs; [ + unstable.youtube-dl + unstable.yt-dlp + mplayer + mpv + mpvReview + + # sanitazion + alphaSafe + sanitizeFolder + + + + # to record your screen + # --------------------- + simplescreenrecorder + screenKey + obs-studio + + # to transcode video material + # --------------------------- + handbrake + ffmpeg-full + + + ]; + }; +} + diff --git a/nixos/machines/cream/configuration.nix b/nixos/machines/cream/configuration.nix index e61faa7..f00348a 100644 --- a/nixos/machines/cream/configuration.nix +++ b/nixos/machines/cream/configuration.nix @@ -73,7 +73,6 @@ }; }; - programs.custom.video.enable = false; programs.custom.steam.enable = true; services.printing.enable = true; diff --git a/nixos/machines/sternchen/configuration.nix b/nixos/machines/sternchen/configuration.nix index 57c1d83..b2f3322 100644 --- a/nixos/machines/sternchen/configuration.nix +++ b/nixos/machines/sternchen/configuration.nix @@ -45,7 +45,6 @@ }; programs.custom.steam.enable = false; - programs.custom.video.enable = false; # keyboard fiddling i18n.defaultLocale = "de_DE.UTF-8"; diff --git a/nixos/machines/sterni/configuration.nix b/nixos/machines/sterni/configuration.nix index 48b8678..8e86ead 100644 --- a/nixos/machines/sterni/configuration.nix +++ b/nixos/machines/sterni/configuration.nix @@ -27,7 +27,6 @@ users.users.mainUser.extraGroups = [ "adbusers" "video" ]; programs.custom.steam.enable = false; - programs.custom.video.enable = false; services.printing.enable = false; services.nginx.enable = true; diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index 0a36464..38e6f66 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -28,7 +28,7 @@ ./programs/steam.nix #./programs/taskwarrior.nix ./programs/urxvt.nix - ./programs/video.nix + #./programs/video.nix ./programs/vim.nix ./programs/xterm.nix diff --git a/nixos/modules/programs/video.nix b/nixos/modules/programs/video.nix index e8ad397..fda7bd8 100644 --- a/nixos/modules/programs/video.nix +++ b/nixos/modules/programs/video.nix @@ -50,6 +50,29 @@ let (position: screenKeyScript { inherit size position; }))); }; + + mpvReview = + let + moveToDir = key: dir: pkgs.writeText "move-with-${key}.lua" '' + tmp_dir = "${dir}" + + function move_current_track_${key}() + track = mp.get_property("path") + os.execute("mkdir -p '" .. tmp_dir .. "'") + os.execute("mv '" .. track .. "' '" .. tmp_dir .. "'") + print("moved '" .. track .. "' to " .. tmp_dir) + end + + mp.add_key_binding("${key}", "move_current_track_${key}", move_current_track_${key}) + ''; + delete = moveToDir "D" "./.graveyard"; + good = moveToDir "G" "./.good"; + in + pkgs.writers.writeDashBin "mpv-review" '' + exec ${pkgs.mpv}/bin/mpv --no-config --script=${delete} --script=${good} "$@" + ''; + + in { @@ -61,6 +84,8 @@ in unstable.yt-dlp mplayer mpv + mpvReview + # to record your screen # ---------------------