Last active
January 4, 2018 10:53
-
-
Save maxpeterson/ebab9079b852224c43d1562c5f7bdf83 to your computer and use it in GitHub Desktop.
Reencode music files from alac to aac
This file contains hidden or 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 | |
folder=$1; shift | |
if test "$folder" == "" ; then | |
echo "Please provide a folder containing music to re-encode." | |
exit 1 | |
fi | |
old_codec=${1:-alac} | |
new_codec=${2:-aac} | |
destdir=$(dirname "$folder")/Encoded | |
echo "Writing re-encoded files to $destdir" | |
echo | |
find "$folder" -type f -not -name .\* | while read file; do | |
#echo "$file" | |
outfile=${file/#$folder/$destdir} | |
if [ ! -f "$outfile" ]; then | |
streams=$(ffprobe -loglevel quiet -show_streams "$file") | |
if test "$?" == "1"; then | |
echo "ffprobe error $file: $streams" | |
else | |
echo "$streams" | grep -q -e "codec_name=$old_codec"; | |
if test "$?" == "0"; then | |
dir=$(dirname "$outfile") | |
[[ -d "$dir" ]] || mkdir -p "$dir"; | |
echo "encoding $file" | |
ffmpeg -nostdin -loglevel error -y -i "$file" -strict experimental -vn -sn -c:a "$new_codec" "$outfile"; | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will create files in
~/Music/iTunes/iTunes\ Media/Encoded/..
folder based on files in~/Music/iTunes/iTunes\ Media/Music/...
.Copy other files with