Tuesday, 8 September 2009

Audio Conversion with ffmpeg

I was looking to convert a set of arbitrary audio files to mp3 so I could play them on my mp3 player. My first thought was mencoder but unfortunately I could find no way to encode from an audio stream without a container, mplayer kept saying video was required.

After some searching ffmpeg was suggested:

ffmpeg -i name_file.aac -vn -acodec libmp3lame name_file.mp3
ffmpeg -i name_file.aac -vn -acodec libmp3lame -aq 6 name_file.mp3
ffmpeg -i name_file.aac -vn -acodec libmp3lame -ar 44100 -ac 2 -ab 128000 name_file.mp3

This results in the following script to convert all files in the current directory with the given extension to mp3:
#!/bin/bash
for i in *.$1; do ffmpeg -i $i -vn -acodec libmp3lame $i.mp3 done;
Note that the file names cannot contain spaces or the script will break.

No comments:

Post a Comment