From d6626110c281e2e872c45fec219086567ac09097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Wed, 28 May 2025 22:04:56 +0200 Subject: [PATCH] System Gen47 @ 2025-05-28-22:04:55 by jonas@monolith --- hosts/monolith/configuration.nix | 4 +- pkgs/default.nix | 4 +- .../transcode-davinci-resolve.sh | 37 +++++++++++++------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/hosts/monolith/configuration.nix b/hosts/monolith/configuration.nix index f883bc1..9004b93 100644 --- a/hosts/monolith/configuration.nix +++ b/hosts/monolith/configuration.nix @@ -69,8 +69,8 @@ borgmatic chromium davinci-resolve - discord digikam + discord docker docker-compose drawio @@ -79,6 +79,7 @@ firefox gimp git + hive.transcode-davinci-resolve insomnia kdePackages.kdenlive krita @@ -97,7 +98,6 @@ ranger sops spotify - transcode-davinci-resolve vim vlc vscode diff --git a/pkgs/default.nix b/pkgs/default.nix index 465763f..f634f73 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,3 +1,5 @@ _: prev: { - transcode-davinci-resolve = prev.callPackage ./transcode-davinci-resolve {}; + hive = { + transcode-davinci-resolve = prev.callPackage ./transcode-davinci-resolve {}; + }; } diff --git a/pkgs/transcode-davinci-resolve/transcode-davinci-resolve.sh b/pkgs/transcode-davinci-resolve/transcode-davinci-resolve.sh index 889cb58..39378fd 100644 --- a/pkgs/transcode-davinci-resolve/transcode-davinci-resolve.sh +++ b/pkgs/transcode-davinci-resolve/transcode-davinci-resolve.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -set -e - where="${1:-.}" selection=$(find "$where" -type f | fzf --multi --preview 'ffprobe -v error -show_format -show_streams {}' --preview-window=up:wrap) @@ -16,12 +14,13 @@ else fi function transcode_job { - local file="$1" + local ifile="$1" local output_dir="$2" local flatten="$3" - local where=$4 - local fname=$(basename "$file") - local segment=$(realpath --relative-to="$where" "$file") + local where="$4" + local fname=$(basename "$ifile") + local segment=$(realpath --relative-to="$where" "$ifile") + if [ "$flatten" = true ]; then output_file="$output_dir/$fname.mov" @@ -29,16 +28,30 @@ function transcode_job { output_file="$output_dir/$segment.mov" fi - mkdir -p "$(dirname "$output_file")" >> log.txt + tmp_file=$(mktemp) - ffmpeg -i "$file" -c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p -c:a pcm_s16le "$output_file" || true + mkdir -p "$(dirname "$output_file")" + if ffmpeg -y -i "$ifile" -c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p -c:a pcm_s16le "$output_file" 2>> "$tmp_file"; + then + rm -f "$tmp_file" + else + # gum log "Failed to transcode $ifile. Check ./error.log for details." + cat "$tmp_file" >> error.log + rm -f "$tmp_file" + + fi } export -f transcode_job +mapfile -t files <<< "$selection" +len=${#files[@]} i=1 -len=$(echo "$selection" | wc -l) -while IFS= read -r file; do - gum spin --spinner dot --title "[$i/$len] Transcoding $file" -- bash -c "source <(declare -f transcode_job); transcode_job \"$file\" \"$output_dir\" \"$flatten\" \"$where\"" +for file in "${files[@]}"; do + if [[ -f "$file" ]]; then + gum spin --spinner dot --title "[$i/$len] Transcoding $file" -- bash -c "source <(declare -f transcode_job); transcode_job \"$file\" \"$output_dir\" \"$flatten\" \"$where\"" + else + echo "Skipping invalid file: $file" >&2 + fi ((i++)) -done <<< "$selection" +done