Skip to content

Instantly share code, notes, and snippets.

@rjeczalik
Last active December 25, 2015 12:59
Show Gist options
  • Save rjeczalik/6980503 to your computer and use it in GitHub Desktop.
Save rjeczalik/6980503 to your computer and use it in GitHub Desktop.
converts m4a to ogg (lazy way to workaround an issue with most recent mpd from homebrew, which apparently does not like m4a)
#!/usr/bin/env bash
to-ogg() {
local src=
local dst=
{
[ ${#} == 0 ] && src=. && dst=.
} || {
[ ${#} == 1 ] &&
[ -d "${1}" ] && src="${1}" && dst="${src}"
} || {
[ ${#} == 2 ] &&
[ -d "${1}" ] && src="${1}" &&
[ -d "${2}" ] && dst="${2}"
} && {
local log=`mktemp /tmp/to-ogg.XXXXXX`
local src_file
for src_file in "${src}"/*.m4a; do
local dst_filename="${src_file##*/}"
local dst_file="${dst}/${dst_filename%*m4a}ogg"
[ -f "${dst_file}" ] && {
echo "# skipping \"${src_file}\", \"${dst_file}\" already exists"
} || {
echo "# converting \"${src_file}\""
ffmpeg -i "${src_file}" -acodec vorbis -strict -2 -aq 60 -vn -ac 2 "${dst_file}" 1>>"${log}" 2>&1 || echo "! converting \"${src_file}\" failed"
}
done
echo "# [ log ${log} ]"
return 0
}
echo "usage: to-ogg [<src-dir=./> [<dest-dir=src-dir>]]" 1>&2
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment