Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Last active November 15, 2017 07:20
Show Gist options
  • Save rchrd2/3c97b5aaa01780d57563 to your computer and use it in GitHub Desktop.
Save rchrd2/3c97b5aaa01780d57563 to your computer and use it in GitHub Desktop.
wav2mp3
                     
 ___       ___     ____     __    __     ______      __    __     _____   _____   
(  (       )  )   (    )    ) )  ( (    (____  \     \ \  / /    (  __ \  )__  \  
 \  \  _  /  /    / /\ \   ( (    ) )        ) /     () \/ ()     ) )_) )  __) /  
  \  \/ \/  /    ( (__) )   \ \  / /    __  / /      / _  _ \    (  ___/  (__ (   
   )   _   (      )    (     \ \/ /    /  \/ / __   / / \/ \ \    ) )        \ \  
   \  ( )  /     /  /\  \     \  /    ( () \__/ /  /_/      \_\  ( (      ___/  ) 
    \_/ \_/     /__(  )__\     \/      \__\____(  (/          \) /__\     )____/  
                                                                                  

Summary

Helper to convert wav to mp3 using ffmpeg.

Usage

./wav2mp3.sh example.wav

This generates one files

  • example.mp3 -- this is the mp3

Requirements

  • ffmpeg (brew install ffmpeg)

Release Notes

  • 11/14/2017 -- Updated to work with file globs
  • 02/07/2013 -- Pushed to Github®

Author

Richard Caceres

Ascii art generated at http://patorjk.com/software/taag/

License

MIT

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#/bin/bash
# Example Usage:
#
# wav2mp3.sh STE-000.wav
# wav2mp3.sh *.wav
#
# Author: Richard (@rchrd2)
# See: https://gist.github.com/rchrd2/3c97b5aaa01780d57563
BIT_RATE=320
# Validate ffmpeg is installed
command -v ffmpeg >/dev/null 2>&1 || { echo >&2 "please install ffmpeg (brew install ffmpeg)"; exit 1; }
FILES=$@
for f in $FILES; do
if [ -d $f ]; then continue; fi
dest=$(echo $f | sed 's/\.wav$/.mp3/g')
if [ -f "$dest" ]; then
echo "File '$dest' already exists."
else
# Convert wav to mp3 using ffmpeg
ffmpeg -i "$f" -ab "${BIT_RATE}k" "$dest"
fi
done
echo "Done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment