From 39a5c0ca67241747c2453b5bb77e260fbc192e46 Mon Sep 17 00:00:00 2001 From: caem Date: Mon, 6 May 2024 18:31:43 +0200 Subject: [PATCH] Use the ogg container instead and fix an edge case Using the ogg container allows to also embed cover images while still using the opus codec. Also fixed an edge case that would make the script fail if the first thing it iterated on was a regular file which didn't require conversion if the parent directory wasn't already created. --- flac2opus_collection.bash | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/flac2opus_collection.bash b/flac2opus_collection.bash index 62ada4c..7bb4ec8 100755 --- a/flac2opus_collection.bash +++ b/flac2opus_collection.bash @@ -125,7 +125,7 @@ get_total_count() { for item in "$dir"/*; do if [ -f "$item" ]; then new_file="${item/"$INPUT_DIR"/"$OUTPUT_DIR"}" - new_file="${new_file/".flac"/".opus"}" + new_file="${new_file/".flac"/".ogg"}" if [ ! -f "$new_file" ] && [[ "$item" == *".flac" ]]; then ((total_count+=1)) elif [[ "$item" == *".flac" ]]; then @@ -156,13 +156,17 @@ iterate_dirs() { item="${item/\$/"\\$"}" if [ -f "$item" ]; then new_file="${item/"$INPUT_DIR"/"$OUTPUT_DIR"}" - new_file="${new_file/".flac"/".opus"}" + new_file="${new_file/".flac"/".ogg"}" if [ ! -f "$new_file" ]; then if [[ "$item" == *".flac" ]]; then ((count+=1)) conversions+=("printf '[%s/%s] \e[92m%s\e[0m -> \e[93m%s\e[0m\n' $count $total_count \ - \"$item\" \"$new_file\" && ffmpeg -hide_banner -loglevel error -i \"$item\" -vbr \"$VBR\" -b:a \"$BITRATE\" \"$new_file\" > /dev/null") + \"$item\" \"$new_file\" && ffmpeg -hide_banner -loglevel error -i \"$item\" -c:a libopus -vbr \"$VBR\" -b:a \"$BITRATE\" \"$new_file\" > /dev/null") else + new_dir=$(dirname "${item/"$INPUT_DIR"/"$OUTPUT_DIR"}") + if [ ! -d "$new_dir" ]; then + mkdir -p "$new_dir" + fi echo "Copied $(basename "$item")" cp -f "$item" "$new_file" fi