media-tools/to_vp9/to_vp9.sh

86 lines
2.3 KiB
Bash
Raw Normal View History

2023-07-25 00:52:25 +02:00
#!/bin/bash
# set shopt-options used by this shell-script
# Note, 0 (true) from shopt -q is "false" in a math context.
shopt -q globstar; globstar_set=$?
((globstar_set)) && shopt -s globstar
shopt -q extglob; extglob_set=$?
((extglob_set)) && shopt -s extglob
# return default shopt-options
function finish {
((globstar_set)) && shopt -u globstar
((extglob_set)) && shopt -u extglob
}
trap finish EXIT
print_help() {
printf "Help: not implemented yet"
}
while getopts 'e:dh' flag; do
case "${flag}" in
e) extension+=("$OPTARG");;
d) delete=true;;
h) print_help
exit 0;;
*) exit 1 ;;
esac
done
# Print available encoders
readarray -t encoders <<<$(ffmpeg -encoders -hide_banner|grep vp9)
echo "In FFMPEG verfügbare Encoder:"
for i in "${!encoders[@]}"; do
echo "$i: ${encoders[i]}"
#encoders[i]=$(echo ${encoders[0]} | awk '{print $2}')
done
# Choose an encoder
while :; do
2023-07-25 15:28:00 +02:00
read -r -p "Choose an encoder [0]: " encoder
2023-07-25 00:52:25 +02:00
[[ $encoder =~ ^[0-9]+$ ]] || { echo "Enter a valid number"; continue; }
if ((encoder >= 0 && encoder < ${#encoders[@]})); then
2023-07-25 15:28:00 +02:00
encoder=$(echo "${encoders[$encoder]}" | awk '{print $2}')
2023-07-25 00:52:25 +02:00
break
else
2023-07-25 15:03:31 +02:00
echo "Not a valid encoder, try again"
2023-07-25 00:52:25 +02:00
fi
done
2023-07-25 15:03:31 +02:00
# Choose an GPU, if encoder is GPU accelerated
2023-07-25 16:29:30 +02:00
# ls /sys/class/drm/renderD129/device/consumer*/consumer/ | grep supp
# lspci | grep ' VGA ' | cut -d" " -f 1 | xargs -i lspci -v -s {}
2023-07-25 18:25:46 +02:00
gpu="/dev/dri/renderD129"
# encoder-specific settings
2023-07-25 15:03:31 +02:00
2023-07-25 00:52:25 +02:00
# write array into string
extension="${extension[*]}"
# change separator
extension=${extension// /|}
for file in **/*.@($extension); do
if [[ ${file: -3} == "mkv" ]]; then
file_out="${file%.*}2.mkv"
else file_out="${file%.*}.mkv"; fi
2023-07-25 15:28:00 +02:00
echo "$encoder"
2023-07-25 15:03:31 +02:00
#VP9_vaapi
2023-07-25 18:25:46 +02:00
#there are problems with the -global_quality:v/-q:v settings only being able to make quality worse. Help is appreciated
#not enough tested. So it is still experimental
if [[ $encoder == "vp9_vaapi" ]]; then
ffmpeg -hide_banner -hwaccel vaapi -vaapi_device $gpu -i "$file" -map 0 -c copy -c:v vp9_vaapi -rc_mode CQP -bf 1 -bsf:v vp9_raw_reorder,vp9_superframe -vf 'hwupload' "$file_out"
fi
2023-07-25 15:03:31 +02:00
#VP9_qsv
2023-07-25 17:14:47 +02:00
#was not able to test it. So it is still experimental
2023-07-26 23:17:27 +02:00
#ffmpeg -hide_banner -hwaccel qsv -qsv_device $gpu -i "$file" -c:v av1_qsv -vf 'hwupload' "${file%.*}.mkv"
2023-07-25 15:03:31 +02:00
2023-07-25 18:25:46 +02:00
#libvpx-vp9
#...
2023-07-25 00:52:25 +02:00
done