Skip to content

Instantly share code, notes, and snippets.

@stesee
Created December 26, 2019 22:26
Show Gist options
  • Save stesee/509ea73a1de00136e7e72cf486466b07 to your computer and use it in GitHub Desktop.
Save stesee/509ea73a1de00136e7e72cf486466b07 to your computer and use it in GitHub Desktop.
bash script extracting audio from mp4
#http://askubuntu.com/questions/221026/how-can-i-batch-extract-audio-from-mp4-files-with-ffmpeg-without-decompression#221069
mkdir -p output
# current directory has to contain at least one .mp4 file
for vid in *.mp4; do
codec="$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -print_format csv=p=0 "$vid")"
case "$codec" in
mp3 ) filetype=mp3 ;;
vorbis ) filetype=ogg ;;
aac ) filetype=m4a ;;
* ) filetype= ;;
esac
if [ "$filetype" ]; then
ffmpeg -i "$vid" -vn -acodec copy output/"${vid%.*}"."$filetype"
else
ffmpeg -i "$vid" -vn -acodec libvorbis output/"${vid%.*}".ogg
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment