System Gen111 @ 2025-11-17-02:42:57 by jonas@monolith
This commit is contained in:
parent
bb20341e00
commit
6fac88ecc2
@ -213,7 +213,7 @@
|
||||
};
|
||||
|
||||
devShells.${system} = {
|
||||
transcode-davinci-resolve = (import ./pkgs/transcode-davinci-resolve/shell.nix) {pkgs = nixpkgs.legacyPackages.${system};};
|
||||
bulk-transcode = (import ./pkgs/bulk-transcode/shell.nix) {pkgs = nixpkgs.legacyPackages.${system};};
|
||||
spotify-shortcuts = (import ./pkgs/spotify-shortcuts/shell.nix) {pkgs = nixpkgs.legacyPackages.${system};};
|
||||
};
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ in {
|
||||
++ lib.optionals cfg.video-editing-light [ffmpeg losslesscut-bin]
|
||||
++ lib.optionals cfg.video-editing-heavy [
|
||||
davinci-resolve
|
||||
hive.transcode-davinci-resolve
|
||||
hive.bulk-transcode
|
||||
kdePackages.kdenlive
|
||||
]
|
||||
++ lib.optional cfg.daws bitwig-studio-latest;
|
||||
|
||||
1
pkgs/bulk-transcode/.envrc
Normal file
1
pkgs/bulk-transcode/.envrc
Normal file
@ -0,0 +1 @@
|
||||
use flake ../../#bulk-transcode --show-trace
|
||||
83
pkgs/bulk-transcode/bulk-transcode.sh
Normal file
83
pkgs/bulk-transcode/bulk-transcode.sh
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
declare -rA presets=(
|
||||
[davinci-resolve]="-c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p -c:a pcm_s16le"
|
||||
[instagram]="-vf scale='if(gte(iw/ih,1),1920,-1)':'if(gte(iw/ih,1),-1,1920)' -pix_fmt yuv420p -c:v h264_nvenc -b:v 3500k -b:a 128k -c:a aac -movflags +faststart"
|
||||
[web-generic]="-vf scale='if(gte(iw/ih,1),1920,-1)':'if(gte(iw/ih,1),-1,1920)' -pix_fmt yuv420p -c:v h264_nvenc -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart"
|
||||
[storage]="-c:v hevc_nvenc -preset p7 -b:v 0 -spatial-aq 1 -rc vbr_hq -c:a copy"
|
||||
)
|
||||
declare -rA containers=(
|
||||
[davinci-resolve]="mov"
|
||||
[instagram]="mp4"
|
||||
[web-generic]="mp4"
|
||||
[storage]="mp4"
|
||||
)
|
||||
|
||||
where="${1:-.}"
|
||||
dest="${2:-$where}"
|
||||
|
||||
selection=$(find "$where" -type f | fzf --multi --preview 'ffprobe -v error -show_format -show_streams {}' --preview-window=up:wrap)
|
||||
|
||||
preset=$(
|
||||
printf '%s\n' "${!presets[@]}" | \
|
||||
fzf --multi --prompt "Select a preset"
|
||||
)
|
||||
flags="${presets[$preset]}"
|
||||
container="${containers[$preset]}"
|
||||
|
||||
output_dir=$(find "$dest" -type d ! -name '.*' ! -path '*/.*/*' | fzf --preview 'tree -C {}' --preview-window=up:wrap --prompt "Select output directory: ")
|
||||
|
||||
if gum confirm "Flatten the directory structure?";
|
||||
then
|
||||
flatten=true
|
||||
else
|
||||
flatten=false
|
||||
fi
|
||||
|
||||
|
||||
function transcode_job {
|
||||
local ifile="$1"
|
||||
local output_dir="$2"
|
||||
local flatten="$3"
|
||||
local where="$4"
|
||||
local flags="$5"
|
||||
local container="$6"
|
||||
local fname=$(basename "$ifile")
|
||||
local segment=$(realpath --relative-to="$where" "$ifile")
|
||||
|
||||
|
||||
if [ "$flatten" = true ]; then
|
||||
output_file="$output_dir/$fname.$container"
|
||||
else
|
||||
output_file="$output_dir/$segment.$container"
|
||||
fi
|
||||
|
||||
tmp_file=$(mktemp)
|
||||
|
||||
echo "Running Command: ffmpeg -y -i $ifile $flags $output_file" >> "$tmp_file"
|
||||
|
||||
mkdir -p "$(dirname "$output_file")"
|
||||
|
||||
if ffmpeg -y -i "$ifile" $(echo -n "$flags") "$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
|
||||
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\" \"$flags\" \"$container\""
|
||||
else
|
||||
echo "Skipping invalid file: $file" >&2
|
||||
fi
|
||||
((i++))
|
||||
done
|
||||
@ -12,7 +12,7 @@
|
||||
...
|
||||
}:
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
name = "transcode-davinci-resolve";
|
||||
name = "bulk-transcode";
|
||||
src = ./.;
|
||||
|
||||
buildInputs = [
|
||||
@ -27,9 +27,9 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
install -Dm755 transcode-davinci-resolve.sh $out/bin/transcode-davinci-resolve
|
||||
install -Dm755 bulk-transcode.sh $out/bin/bulk-transcode
|
||||
|
||||
wrapProgram $out/bin/transcode-davinci-resolve \
|
||||
wrapProgram $out/bin/bulk-transcode \
|
||||
--set PATH "${lib.makeBinPath finalAttrs.buildInputs}"
|
||||
'';
|
||||
})
|
||||
@ -2,6 +2,6 @@
|
||||
bin = pkgs.callPackage ./default.nix {};
|
||||
in
|
||||
pkgs.mkShell {
|
||||
name = "transcode-davinci-resolve";
|
||||
name = "bulk-transcode";
|
||||
inputsFrom = [bin];
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
final: _: {
|
||||
hive = {
|
||||
crossover = final.callPackage ./crossover.nix {};
|
||||
transcode-davinci-resolve = final.callPackage ./transcode-davinci-resolve {};
|
||||
bulk-transcode = final.callPackage ./bulk-transcode {};
|
||||
spotify-shortcuts = final.callPackage ./spotify-shortcuts {};
|
||||
layan-qt6 = final.kdePackages.callPackage ./layan-qt6.nix {};
|
||||
};
|
||||
|
||||
@ -1 +0,0 @@
|
||||
use flake ../../#transcode-davinci-resolve --show-trace
|
||||
@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
where="${1:-.}"
|
||||
|
||||
selection=$(find "$where" -type f | fzf --multi --preview 'ffprobe -v error -show_format -show_streams {}' --preview-window=up:wrap)
|
||||
|
||||
output_dir=$(find $HOME -type d ! -name '.*' ! -path '*/.*/*' | fzf --preview 'tree -C {}' --preview-window=up:wrap --prompt "Select output directory: ")
|
||||
|
||||
if gum confirm "Flatten the directory structure?";
|
||||
then
|
||||
flatten=true
|
||||
else
|
||||
flatten=false
|
||||
fi
|
||||
|
||||
function transcode_job {
|
||||
local ifile="$1"
|
||||
local output_dir="$2"
|
||||
local flatten="$3"
|
||||
local where="$4"
|
||||
local fname=$(basename "$ifile")
|
||||
local segment=$(realpath --relative-to="$where" "$ifile")
|
||||
|
||||
|
||||
if [ "$flatten" = true ]; then
|
||||
output_file="$output_dir/$fname.mov"
|
||||
else
|
||||
output_file="$output_dir/$segment.mov"
|
||||
fi
|
||||
|
||||
tmp_file=$(mktemp)
|
||||
|
||||
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
|
||||
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
|
||||
Loading…
x
Reference in New Issue
Block a user