Skip to content

Instantly share code, notes, and snippets.

@stesee
Created December 26, 2019 22:28
Show Gist options
  • Save stesee/849bab6c3792c2dd824f671fd5c389fe to your computer and use it in GitHub Desktop.
Save stesee/849bab6c3792c2dd824f671fd5c389fe to your computer and use it in GitHub Desktop.
bash script extracting audio from mp4 and conditionaly convert or copy to mp3
#http://askubuntu.com/questions/221026/how-can-i-batch-extract-audio-from-mp4-files-with-ffmpeg-without-decompression#221069
mkdir -p outputmp3
# 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 ;;
* ) filetype= ;;
esac
if [ "$filetype" ]; then
ffmpeg -i "$vid" -vn -acodec copy outputmp3/"${vid%.*}"."$filetype"
else
ffmpeg -i "$vid" -vn -acodec mp3 outputmp3/"${vid%.*}".mp3
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment