Skip to content

Instantly share code, notes, and snippets.

@monstermunchkin
Created June 8, 2011 05:39
Show Gist options
  • Save monstermunchkin/1013841 to your computer and use it in GitHub Desktop.
Save monstermunchkin/1013841 to your computer and use it in GitHub Desktop.
Extract audio and add tags for acc files.
#!/bin/bash
if ! [[ -f "$1" ]]; then
exit 1
fi
ftype=$(ffmpeg -i "$1" 2>&1 | grep -o 'Audio:[^,]*' | awk '{print $2}')
fflags='-vn -acodec copy'
case "$ftype" in
'vorbis')
fext='ogg';;
*)
fext="$ftype";;
esac
echo -n "$1 -> ${1%.*}.$fext (codec: $ftype) ... "
fname="${1%.*}"
ffmpeg -i "$1" $fflags "$fname.$fext" 2>/dev/null <<< 'n'
if [[ $? == 0 ]]; then
echo 'done'
mv "$1"{,.done}
else
echo 'failed'
exit 1
fi
if [[ "$fext" == 'aac' ]]; then
echo -n "$fname.$fext -> $fname.m4a ... "
artist=$(sed -rn 'y/_/ /;s/(.*) -.*/\1/p' <<< "$fname")
title=$(sed -rn 'y/_/ /;s/.*- (.*)/\1/p' <<< "$fname")
faad -w "$fname.$fext" 2>/dev/null | faac -w --artist "$artist" \
--title "$title" -o "$fname.m4a" - &>/dev/null
if [[ ${PIPESTATUS[1]} == 0 ]]; then
echo 'done'
rm "$fname.$fext"
else
echo 'failed'
exit 1
fi
fi
exit 0
# vim: set ts=4 sts=4 sw=4 noet:
@monstermunchkin
Copy link
Author

Call with GNU Parallel: parallel -u auex.sh ::: *.flv

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