Convert mp3 files to wav files

I’ve noticed that a few people lately have asked about converting mp3 audio files to wav files. Ideally, one would use MediaConverter. But that app is just plain broken.

I recently wrote a script for this using ffmpeg as the backend for the conversion. You can access a copy of this here:

Of course, this is just a plain text file. Save it to /boot/common/bin (or somewhere else in your path) and make sure the executable bits are set.

Works like a charm, for me anyway, so others may find this useful.

Now… the big item. You may not have the ffmpeg binary on your system (probably don’t). Haiku comes with an ffmpeg plugin, used by the MediaPlayer, for example. But that’s a lib not the binary executable. So, you can grab a current one here:

This is the latest version compiled for Haiku AFAIK. Just download this and unzip to /boot.

However… this binary has a dependency on the SDL libs. You may not have those around, in which case it won’t run. To get those, run this:

installoptionalpackage sdllibs

This installs a BUNCH of stuff, so it make take a few minutes. A bunch of codecs, support libs, etc.

Once you have that you’re good to go right? Probably not. The gives (me anyway) a missing symbol error when trying to load. Shrugs

So, I downloaded the SDL Game Libraries from Haikuware. Here’s the link:

After installing that, all works perfectly.

Now, could you skip the installoptionalpackage step and just use the SDL game libs? I’m not sure, but I don’t think so. Because the ffmpeg binary seems to want access to the libspeex and libvpx libraries which the haikuware package does not include. But I could be wrong about that. In any event, following the steps above should get you a working ffmpeg binary. Once you have this, my script should work fine.

Incidentally, the script above is just a modified version of an earlier one I wrote a couple of years ago for a slightly different purpose: converting flv files to avi.

I found that I was quite often getting youtube videos in flv format when downloading, but Haiku back then didn’t handle them. And MediaConverter didn’t either. So I wrote a ffmpeg front end script for it. It was pretty much about the same except that the convert() function looked like this:

	local  flv=$1
	local base=${flv%.*}    # strip off extension
	local  avi="$base.avi"  # tack on avi extension
$FFmpeg  \
	-i "$flv"      `# input filename`           \
	-f avi         `# use AVI file format`      \
	-vcodec mpeg4  `# encode as mpeg4`          \
	-b 25600000    `# video bitrate=25600 kb/s` \
	-ab 128000     `# audio bitrate=128 kb/s`   \
	-sameq         `# same quality for output video as input` \
	"$avi"         `# output filename`


But then Haiku added flv support, so I don’t really need that particular usage anymore. But it still works.

The latest version of BurnItNow EXP includes a utility “AnyToWave” that does all of the common file conversions such as Mp3, Ogg, Flv, Mp4 and 3gp to wave audio.

The reason you’re getting missing symbols is probably because ffmpeg was built with gcc4 but the installoptional package version of SDL is built with gcc2. So you can probably skip that step.

Interesting that it manages to link against 2.95 versions of libspeex and libvpx but not the rest of the 2.95 libraries!

My reasoning for thinking this is the problem with the linking is that I recently built arnold, an amstrad CPC emulator, and could not get it to (run-time) link against the 2.95 versions of libsdl from installoptionalpackage. Building the same version of libsdl with gcc4 worked, so I rebuilt arnold with gcc2.95 and it worked with the installoptionalpackage versions (no missing symbols errors from run time linker).

This suggests that either libspeex and libvpx are built with gcc4 (unlikely, I think all installoptionalpackages are 2.95) or that for some reason linking to them works between gcc4 and 2.95, which is more likely, but a bit mysterious. Wonder why it works… perhaps down to luck more than anything else…

Munchausen - I finally tested this and, sure enough, you need all three steps.

What I did was take a USB stick that still had the R1A4 image on it. I mounted this and copied over the ffmeg zip and SDL game libs zip (7z actually) along with a couple of sample mp3s onto the home dir to test with. Then copied my script over to the /boot/home/config/bin dir. Also deleted a few files to make some room as space is real tight on the alpha image.

Then I booted up from that USB, uncompressed the ffmpeg and SDL game libs, and then tried to run the script. Loading ffmpeg failed because it could not find And presumably it was trying to load as well. Those two libs are not included on the SDL game libs from Haikuware. So yes, you actually do need to do the ‘installoptionalpackage sdllibs’ step in the middle to get the whole banana.