Skip to content

Instantly share code, notes, and snippets.

@m-mizutani
Created September 13, 2011 14:51
Show Gist options
  • Save m-mizutani/1213987 to your computer and use it in GitHub Desktop.
Save m-mizutani/1213987 to your computer and use it in GitHub Desktop.
Audio file extractor
#!/bin/sh
if [ $# != 1 ]
then
echo 'syntax)' `basename $0` '<movie>'
exit
fi
target=$1
base=`echo $target | sed -e 's@\.[a-z0-9]*$@@g'`
fmt=`ffprobe -i "$target" 2>&1| grep Audio: | sed -e 's@.*Audio: \([a-z0-9]*\) .*@\1@g'`
ffmpeg -i "$target" -map 0:1 -codec copy "$target.$fmt"
cname="$target.$fmt"
if [ "$fmt" == "aac" ]
then
MP4Box -add "$cname" "$target.m4a"
rm "$cname"
cname="$target.m4a"
fmt="m4a"
fi
mv "$cname" "$base.$fmt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment