split configs into two systems...
This commit is contained in:
98
workstation/scripts/ffmpreg.sh
Executable file
98
workstation/scripts/ffmpreg.sh
Executable file
@@ -0,0 +1,98 @@
|
||||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p bash gum trashy fd ripgrep mediainfo
|
||||
|
||||
replace_extension() {
|
||||
local file_basename
|
||||
file_basename=$(basename "$1")
|
||||
echo "${file_basename%.*}.$2"
|
||||
}
|
||||
|
||||
convert_gif() {
|
||||
file_newname=$(replace_extension "$1" gif)
|
||||
ffpb -i "$(realpath "$1")" -vf fps=12,scale=480:-1,smartblur=ls=-0.5 "$file_newname"
|
||||
}
|
||||
|
||||
convert_mp4() {
|
||||
local file_newname
|
||||
file_newname=$(replace_extension "$1" mp4)
|
||||
local file_tempdest=/dev/shm/$file_newname
|
||||
local file_destination
|
||||
file_destination=$(dirname "$(realpath "$1")")/$file_newname
|
||||
ffpb -i "$1" \
|
||||
-c:v libx265 \
|
||||
"$file_tempdest"
|
||||
trash "$1"
|
||||
mv -i "$file_tempdest" "$file_destination"
|
||||
}
|
||||
|
||||
convert_discord() {
|
||||
local file_newname
|
||||
file_newname=$2_$(replace_extension "$1" mp4)
|
||||
local dir_ram=/dev/shm/ffmpeg
|
||||
mkdir -p $dir_ram/{in,out}
|
||||
ffpb -hwaccel cuda -i "$(realpath "$1")" \
|
||||
-c:v h264_nvenc \
|
||||
"$dir_ram"/in/discord.mp4
|
||||
cd "$dir_ram" || exit
|
||||
codec=x264 audio_br=$3 fs=$4 reso=$5 ffmpeg4discord
|
||||
mv "$dir_ram"/out/small_discord.mp4 ~/"$file_newname"
|
||||
command rm -rf "$dir_ram"
|
||||
}
|
||||
|
||||
operation=$(gum choose mp4 discord nitro gif enc265)
|
||||
|
||||
case $operation in
|
||||
1 | mp4)
|
||||
to_convert=()
|
||||
while IFS= read -r file; do
|
||||
to_convert+=("$file")
|
||||
done < <(fd . "$(pwd)" -tf -aL | fzf --multi -i)
|
||||
for file in "${to_convert[@]}"; do
|
||||
convert_mp4 "$file"
|
||||
done
|
||||
;;
|
||||
2 | discord)
|
||||
to_convert=()
|
||||
while IFS= read -r file; do
|
||||
to_convert+=("$file")
|
||||
done < <(fd . "$(pwd)" -tf -aL | fzf --multi -i)
|
||||
for file in "${to_convert[@]}"; do
|
||||
convert_discord "$file" discord 96 8.0 "1280x720"
|
||||
done
|
||||
;;
|
||||
3 | nitro)
|
||||
to_convert=()
|
||||
while IFS= read -r file; do
|
||||
to_convert+=("$file")
|
||||
done < <(fd . "$(pwd)" -tf -aL | fzf --multi -i)
|
||||
for file in "${to_convert[@]}"; do
|
||||
convert_discord "$file" nitro 128 50.0 "1920x1080"
|
||||
done
|
||||
;;
|
||||
4 | gif)
|
||||
to_convert=()
|
||||
while IFS= read -r file; do
|
||||
to_convert+=("$file")
|
||||
done < <(fd . "$(pwd)" -tf -aL | fzf --multi -i)
|
||||
for file in "${to_convert[@]}"; do
|
||||
convert_gif "$file"
|
||||
done
|
||||
;;
|
||||
5 | enc265)
|
||||
to_convert=()
|
||||
extensions=(flv m4v mpg avi mov ts mkv mp4 webm)
|
||||
for ext in "${extensions[@]}"; do
|
||||
while IFS= read -r file; do
|
||||
if ! (mediainfo "$file" | grep Writing\ library | grep -q x265); then
|
||||
to_convert+=("$file")
|
||||
fi
|
||||
done < <(fd . -e "$ext" -tf -aL)
|
||||
done
|
||||
for file in "${to_convert[@]}"; do
|
||||
convert_mp4 "$file"
|
||||
done
|
||||
;;
|
||||
*)
|
||||
echo -n "Please select a valid input"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user