.hive/pkgs/transcode-davinci-resolve/transcode-davinci-resolve.sh

45 lines
1.2 KiB
Bash

#!/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)
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 file="$1"
local output_dir="$2"
local flatten="$3"
local where=$4
local fname=$(basename "$file")
local segment=$(realpath --relative-to="$where" "$file")
if [ "$flatten" = true ]; then
output_file="$output_dir/$fname.mov"
else
output_file="$output_dir/$segment.mov"
fi
mkdir -p "$(dirname "$output_file")" >> log.txt
ffmpeg -i "$file" -c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p -c:a pcm_s16le "$output_file" || true
}
export -f transcode_job
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\""
((i++))
done <<< "$selection"