Skip to content

Instantly share code, notes, and snippets.

@spirillen
Last active May 6, 2020 20:21
Show Gist options
  • Save spirillen/6333f73da3fa4fbf78a9cdd0a2750b0e to your computer and use it in GitHub Desktop.
Save spirillen/6333f73da3fa4fbf78a9cdd0a2750b0e to your computer and use it in GitHub Desktop.
Convert almost any media by extension to m4a
#!/usr/bin/env bash
# This script convert flac files into ALAC m4a
# Execute it by calling this script and append full path to dir as
# flac_mp4.sh "/media/joakim/VERBATIM/Avril Lavigne/"
# you can use "${PWD}" if you which to execute this script from
# current dir
# exit on any errors
set -e #-x
_ext=(flac) # e.g. flac mp4 webm opus mp3
_basedir="${1}"
# change to basedir
printf "You are converting from ${_basedir}\n"
cd "${_basedir}"
# Find any files in subfolders and add them to the array
readarray -d '' array < <(for i in "${_ext[@]}"; do find . -type f -iname "*.$i" -print0 ; done)
for i in "${array[@]}"
do printf "converting $i\n"
#ffmpeg -i "$i" -map 0:a:0 -y -v 0 -c:v copy -c:a alac -map_chapters -1 "${i%.*}".m4a && rm -f "$i"
ffmpeg -i "$i" -map 0:a:0 -y -v 0 -c:v copy -c:a alac -map_chapters -1 "${i%.*}".m4a
done
# Some sources had chapters which broke conversion
#mkdir -p "${subdir}/chap"
#ffmpeg -i "$i" -y -v 0 -c copy -map_chapters -1 "chap/${i}"
@spirillen
Copy link
Author

Flipped default delete behavior....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment