From a7f83a231ee167c2b4b583ccda3eb036ff9f7828 Mon Sep 17 00:00:00 2001 From: Leaced Date: Fri, 24 Mar 2023 17:03:07 +0100 Subject: [PATCH] Added default option for multiple audio channels --- to_opus.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/to_opus.sh b/to_opus.sh index 8396a50..beffc55 100644 --- a/to_opus.sh +++ b/to_opus.sh @@ -28,6 +28,12 @@ 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) + streams=$(echo "$channels" | wc -l) + if [ streams -gt 1 ]; then + echo "Error: Automatic Bitrate is not supported for files with multiple audiostreams. The default bitrate of 128k will be used" + channels="2" + fi + case $channels in 1) bitrate="64k";; 2) bitrate="128k";; @@ -37,7 +43,7 @@ for file in **/*.@($extension); do 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" + ffmpeg -threads 4 -v 0 -i "$file" -map 0 -c:a libopus -b:a $bitrate "${file%.*}.opus" && rm "$file" done exit 0