From 3005a70e6ff4519e9f350a45fce6a415baccbec5 Mon Sep 17 00:00:00 2001 From: Leaced Date: Fri, 24 Mar 2023 16:40:26 +0100 Subject: [PATCH] Add files via upload Added automatic bitrate --- to_opus.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/to_opus.sh b/to_opus.sh index 1dcdbad..8396a50 100644 --- a/to_opus.sh +++ b/to_opus.sh @@ -14,15 +14,30 @@ function finish { } trap finish EXIT + # setting default extension to mp3 if [ $# -eq 0 ]; then extension="mp3" else extension=$@ + extension=${extension// /|} fi -for file in **/*.@(${extension// /|}); do - ffmpeg -threads 4 -v 0 -i $file -c:a libopus -b:a 128k "${file%.*}.opus" && rm "$file" + +echo "extension is $extension" + +for file in **/*.@($extension); do + channels=$(ffprobe "$file" -show_entries stream=channels -select_streams a -of compact=p=0:nk=1 -v 0) + case $channels in + 1) bitrate="64k";; + 2) bitrate="128k";; + 6) bitrate="256k";; + 8) bitrate="450k";; + *) continue;; + esac + # https://wiki.xiph.org/Opus_Recommended_Settings + + ffmpeg -threads 4 -v 0 -i "$file" -c:a libopus -b:a $bitrate "${file%.*}.opus" && rm "$file" done exit 0