Skip to content

Instantly share code, notes, and snippets.

@AndyA
Last active August 30, 2016 16:06
Show Gist options
  • Save AndyA/6e0ecff6fc3d965b3423540637f10f20 to your computer and use it in GitHub Desktop.
Save AndyA/6e0ecff6fc3d965b3423540637f10f20 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Finds all *.flac files and produces corresponding *.m4a ALAC versions
#
# Usage: flac2alac <file|dir>...
{
for obj in "$@"; do
if [ -f "$obj" ]; then
echo "$obj"
elif [ -d "$obj" ]; then
find "$obj" -iname '*.flac'
fi
done
} | while read src; do
dst="${src%.*}.m4a"
if [ "$src" -nt "$dst" ]; then
echo "$src -> $dst"
tmp="${src%.*}.tmp.m4a"
ffmpeg -i "$src" \
-nostdin \
-vn \
-c:a alac \
-y "$tmp" && mv "$tmp" "$dst"
# ffmpeg doesn't exit via SIGINT when it gets SIGINT
[ $? == 255 ] && exit
fi
done
# vim:ts=2:sw=2:sts=2:et:ft=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment