Created
August 27, 2014 01:13
-
-
Save jcracknell/67111e67d50f7fee497f to your computer and use it in GitHub Desktop.
Transcodes a tree of FLAC files to OPUS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# transcode.sh | |
# | |
# Transcodes a tree of FLAC files in a specified source directory to a matching tree of | |
# Opus files in the specified destination directory. | |
scriptName=$(basename "$0") | |
sourceDirectory="${1%/}" | |
destinationDirectory="${2%/}" | |
[ -d "$sourceDirectory" -a "$destinationDirectory" ] || { | |
echo $scriptName - Transcodes a tree of flac files to Opus. | |
echo Usage: $scriptName source-dir dest-dir | |
exit 1 | |
} | |
function flac2opus() { sourceDirectory="$1"; destinationDirectory="$2"; flacFile="$3"; | |
opusFile="${destinationDirectory}/$(realpath --relative-to "$sourceDirectory" "${flacFile%%.flac}.opus")" | |
[ -e "$opusFile" ] && return 0 | |
echo "[$flacFile] -> [$opusFile]" | |
[ -d "$(dirname "$opusFile")" ] || mkdir -p "$(dirname "$opusFile")" | |
flac -d -c -s "$flacFile" | \ | |
opusenc --quiet --bitrate 192 \ | |
--comment "$(metaflac --show-tag=artist "$flacFile")" \ | |
--comment "$(metaflac --show-tag=album "$flacFile")" \ | |
--comment "$(metaflac --show-tag=tracknumber "$flacFile")" \ | |
--comment "$(metaflac --show-tag=title "$flacFile")" \ | |
--comment "$(metaflac --show-tag=genre "$flacFile")" \ | |
--comment "$(metaflac --show-tag=date "$flacFile")" \ | |
- "$opusFile" | |
} | |
export -f flac2opus | |
find "$sourceDirectory" -type f | grep -E '\.flac$' | parallel --ungroup --nice 20 flac2opus \'"$sourceDirectory"\' \'"$destinationDirectory"\' "{}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment