added flag for deletion

...
This commit is contained in:
esche 2023-07-07 23:23:58 +02:00
parent 85a3f96e01
commit d74998833b

View file

@ -18,9 +18,10 @@ print_help() {
printf "Help: not implemented yet"
}
while getopts 'e:' flag; do
while getopts 'e:dh' flag; do
case "${flag}" in
e) extension+=("$OPTARG");;
d) delete="true";;
h) print_help
exit 0;;
*) exit 1 ;;
@ -40,14 +41,11 @@ for file in **/*.@($extension); do
readarray -t channels <<<"$(ffprobe -v error -select_streams a -show_entries stream=channels -of compact=p=0:nk=1 "$file")"
# array over the bitrates of all streams
readarray -t bitrates <<<"$(ffprobe -v error -select_streams a -show_entries stream=bit_rate -of compact=p=0:nk=1 "$file")"
# number of audiostreams
audiostreams=${#channels[@]}
# set a channel dependend bitrate for every audio stream
# https://wiki.xiph.org/Opus_Recommended_Settings
# to use ffmpegs default just comment out this block
bitrate_settings=""
for ((index=0; index<audiostreams;index++)); do
for ((index=0; index<${#channels[@]};index++)); do
if [[ ${channels[index]} -eq 1 ]]; then
if [[ $bitrates == 'N/A' || ${bitrates[index]} -gt 64000 ]]; then bitrate_settings="$bitrate_settings-b:a:$index 64k "; fi
elif [[ ${channels[index]} -eq 2 ]]; then
@ -61,12 +59,12 @@ for file in **/*.@($extension); do
# use mkv for videos and for multiple audio streams
is_video=$(ffprobe -v error -select_streams V -show_entries stream=codec_type "$file")
if [[ ${#channels[@]} -gt 1 || -n "$is_video" ]]; then
command="ffmpeg -i \"$file\" -map 0 -map -0:d -map -0:t -c copy -c:a libopus $bitrate_settings -v info -hide_banner \"${file%.*}.mkv\""
ffmpeg -i "$file" -map 0 -map -0:d -map -0:t -c copy -c:a libopus $bitrate_settings-v info -hide_banner "${file%.*}.mkv" &&
if [[ delete="true" ]]; then rm "$file"; fi
else
command="ffmpeg -i \"$file\" $bitrate_settings-v info -hide_banner \"${file%.*}.opus\""
ffmpeg -i "$file" $bitrate_settings-v info -hide_banner "${file%.*}.opus" &&
if [[ delete="true" ]]; then rm "$file"; fi
fi
eval "$command" #&& rm "$file"
done
exit 0