iEFdev

Code, Computers & Random Junk

Function to Convert Sounds to Mp3

Just a small function to create mp3-files with ffmpeg Just a small function or snippet to add to your .bash_functions file.

To convert the sound, the code is just:

ffmpeg -i "$1" -ab 320k $(echo "${1%.*}.mp3"

That just about it… But, to make a function of it - let’s add a few more xtras.

Check if ffmpeg is installed…

[[ ! `type ffmpeg 2> /dev/null` ]] && echo "$FUNCNAME: Please install 'ffmpeg'..." && return 1;

And convert blanks to under_scores…

sed 's/[[:space:]]/_/g'

Now together, the function will look like:

1
2
3
4
5
6
# ffmpeg - 320k mp3
function 2mp3()
{
  [[ ! `type ffmpeg 2> /dev/null` ]] && echo "$FUNCNAME: Please install 'ffmpeg'..." && return 1;
  ffmpeg -i "$1" -ab 320k $(echo "${1%.*}.mp3" | sed 's/[[:space:]]/_/g');
}

When using 2mp3() - the mp3 file info will look something like:

Screendump from iTunes.


To use other/lower values than 320… there are a few example in the post: Convert Sound to Mp3 With ‘Ffmpeg’.


Happy hacking…

/Eric

Comments