Strip WAV headers from WAV-embedded MP3-files

Posted by: smu

Strip WAV headers from WAV-embedded MP3-files - 18/03/2003 19:24

Hi.

I have some MP3 files which someone (quite idiotically) embedded into WAV files. Now I need to strip these headers, because the empeg (or at least jemplode) does not recognize these as valid MP3 files. Does anyone know of a command line tool to do this?

Ciao,
Sven
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 18/03/2003 19:59

I can't seem to find a tool, but it shouldn't be too hard to write one, based on the RIFF spec.
Posted by: Ezekiel

Re: Strip WAV headers from WAV-embedded MP3-files - 18/03/2003 21:08

Have you tried the repair options in Mp3 Tag Studio?

-Zeke
Posted by: simspos

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 02:47

Found this link, seems to do what you want, but I have no experience of it.

--------------

http://minnie.tuhs.org/pipermail/mp3encoder/2002-February/004595.html

Hi Jaroslav,

You could try "WaveMP3" rel. 1.2

Adds/strips a Wave Riff header to/from your MP3 files.

http://home.pi.be/~mk442837/
http://home.pi.be/~mk442837/wavemp3.zip
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 11:07

Does MP3 Tag Studio have a command line interface? I don't think so. And I already have a graphical client which can handle complete directories (not recursively descending into subdirs though): WaveMP3

Ciao,
Sven
Posted by: Ezekiel

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 13:40

Sorry, didn't see the command line bit on your post, I tend to skim.

Thanks for the scarcasm though, it's really [censored] appreciated. Ass.

I'm done.

-Zeke
Posted by: tfabris

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 14:00

Hey, lighten up... I don't think that was sarcasm. I think he genuinely wanted to know whether or not MP3TS had a command line interface. Many GUI applications do. I use MP3TS every day and I still don't know whether it has a command line interface.
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 14:08

Hi.

Tony is half right. I really wanted to know wether MP3TS has a command line interface or not. I can't deny a little bit of sarcasm though. Sorry it made you feel bad.

Ciao,
Sven
Posted by: Ezekiel

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 17:45

That's OK. Sorry for having to putting up with my nasty reply. Bad afternoon and not enough food. Your post triggered a bit of rage. I really didn't see the bit about the command line. I know Magnus stops by the BBS every so often. I didn't see anything useful in the Help files.

-Zeke
Posted by: Ezekiel

Re: Strip WAV headers from WAV-embedded MP3-files - 19/03/2003 17:52

http://cbothamy.free.fr/projects/id3ren/

May help or serve as a starting point for a roll your own. Haven't tried it.

-Zeke
Posted by: jarob10

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 00:50

In reply to:

http://cbothamy.free.fr/projects/id3ren/

May help or serve as a starting point for a roll your own. Haven't tried it.




Anyone aware of a similar program to this that can handle id3v2 tags ? The one linked ablove cant (currently). It needs to be command line and windows compatible.

If MP3TS got command line support, that would obviously be the perfect solution.
Posted by: simspos

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 03:15

What's with the "command line only" criteria. Isn't it all about getting the job done???

confused, Sim
Posted by: jarob10

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 05:36

In reply to:

What's with the "command line only" criteria. Isn't it all about getting the job done???




batch file integration.

For me, at least.
Posted by: simspos

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 09:40

Arrrr, that makes a lot of sense - just couldn't see the reasoning - stupid me

Cheers, Sim
Posted by: JeffS

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 09:56

If no one comes up with anything by the end of today I might be able to help. In a project I used to work on we had some utilities we’d written to handle reading/writing WAV files. I’ll have to dig out the code and try to remember exactly how it all worked, but if stripping out the header is all you need I think I can probably create a small command-line utility to do it for you after I get off work.
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 12:02

[id3ren]

Seems to be quite useful and I can probably use it to solve another problem I'm having. I can't see an option to remove WAV/RIFF headers though.

Ciao,
Sven
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 12:07

That would be really nice, and indeed, I only need to remove the RIFF headers from an WAV encapsulated MP3 file. And this encapsulation really seems to consist of nothing else but a WAV file header.

cu,
Sven
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 12:18

Do you know that the WAV file contains only one RIFF chunk? If so, you can just strip off the first twenty bytes of the file. If you don't know, then you'll have to parse the headers to find where the chunks begin and end, and strip each chunk's header out individually.

It should be pretty easy to determine if there's more than one chunk per file or not. Search for the four-character strings "fmt " and "data". If you see more than one, chances are that it's got more than one chunk, and you'll need a vaguely intelligent program to fix it. If there's not, then you should just be able to strip the first twent bytes off.

Under unix, you should be able to
strings file.wav | egrep '(fmt )|(data)'
What OS are you using? Could Perl be used?
Posted by: JeffS

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 12:51

What OS are you using?

Yes, I'd need to know this if I was going to write a utility. Also, I believe Bitt's correct in that it really will be nothing more than deleting the first few bytes, depending on your file(s).
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 12:52

Do you know that the WAV file contains only one RIFF chunk?

I am not certain about this. I handled a few sample file with WaveMP3, and it removed more than just 20 bytes from some of the files, but I can't remember how much exactly.

The grep you proposed returns two matches on each file, one beeing "WAVEfmt " and one being "data".

Regarding the OS: The files reside on a Linux (SAMBA) file server, while I usually use Windows for most other things (well: eMail, Office (though, ironically, mostly LaTeX), webbrowsing etc.) because my notebook doesn't run too well under Linux and I don't have the time to find out why. So basically, both Windows and Linux could be used for this task. And Perl is available on both systems, perl 5.6.1 in both cases.

cu,
sven
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 13:03

Do you know that the WAV file contains only one RIFF chunk?

I am not certain about this. I handled a few sample file with WaveMP3, and it removed more than just 20 bytes from some of the files, but I can't remember how much exactly. I ran it on oone more file just now, and WaveMP3 removed a total of 70 Bytes.

The grep you proposed returns two matches on each file, one beeing "WAVEfmt " and one being "data".

Regarding the OS: The files reside on a Linux (SAMBA) file server, while I usually use Windows for most other things (well: eMail, Office (though, ironically, mostly LaTeX), webbrowsing etc.) because my notebook doesn't run too well under Linux and I don't have the time to find out why. So basically, both Windows and Linux could be used for this task. And Perl is available on both systems, perl 5.6.1 in both cases.

cu,
sven
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 13:07

The fmt chunk, I believe, is metadata. I wouldn't have expected that to be there, but it shouldn't be too difficult to remove. At the same time, it does mean that it will be slightly more complicated than chopping off the first n bytes of data, as I don't think that we can rely on the fact that the fmt chunk will always be of a particular length.

Can you send me a copy of one of the shorter files? I can probably get some perl working in a few minutes.
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 13:30

The smallest file I can verify to really be with a valid RIFF encapsulation is about 6MB in size and available for download at http://www.incase.de/file1.wav in about ten minutes while the smallest file which looks like it is with RIFF encapsulation is about 700kB in size and available at http://www.incase.de/file2.wav.

Thanks for the offer.

[Edit: Both files are available now.]

Ciao,
Sven
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 14:36

This is nice....

file1.wav isn't really a valid RIFF file. It's close and I can hack around it, but its data chunk (where it stores the actual mp3 data) has its length specified incorrectly. The ID3v1 tag lies just outside the chunk proper. file2.wav doesn't have a ID3v1 tag, so I can't tell if this is common or bad just in this case. Anyway, I've hacked around it. Give me a few and it'll be done.
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 14:58

I added an id3 tag (artist) to the smaller file and uploaded it as http://www.incase.de/file2.wav.

cu and thnx alot,
Sven
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 15:14

I'm sure there's a bug or two, but here you go. It strips out the "data" chunk, which seems to be where the mp3 file is kept. I have tried to make it so that it will write multiple "data" chunks to the different files. I imagine that shouldn't happen, though.

There's a debug flag for printing out some additional data and a currdir flag for writing output to the current directory, even if the file was specified as ``../file.wav'' or whatever. Both are off as posted. You'll have to edit the source to change them; just change the appropriate variable to 1 instead of 0.

It can take multiple files as arguments, and will skip over those that aren't valid RIFF files.

It's not the prettiest code, but it should get the job done.

Let me know if it works.

Edit: There's a bug here. Don't use this one.
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 15:18

I don't see any ID3v1 tags in there. In fact, it's identical to the file2.wav you posted earlier.

Edit: Oh, I see. You meant file3.wav. It's even worse. It just had a tag tacked onto the end of the whole thing. Actually, that might be true of file1, too, except it happened to have the "data" chunk as the final chunk.

Hang on and I'll fix my code.
Posted by: JeffS

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 15:28

It appears Bitt has you all fixed up, so I'll assume you don't need me to dig out those wav headers tonight . . . My wife will be glad to have me for another hour! Let me know if I can help at all.
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 15:34

Okay. Here it is again.
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 15:35

I think your wav headers might have failed anyway. It seems that ID3v1 tags were just tacked on to the end of the files in some cases, outside RIFF encapsulation.
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 20/03/2003 16:15

More RIFF data and one final upload with tidier stdout messages.
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 21/03/2003 12:39

Fantastic, it works like a charm and even handles files gracefully WaveMP3 wouldn't even touch (telling me it only treats WAV embedded Layer 3 files, which is basically what I told it to do).

Thanks a lot, I definitely owe you a drink or two, if we ever meet. Or do you have a paypal account?

cu,
Sven

Edit: Hmm, how far is Raleigh from Charlotte? I will be at Charlotte for a few days or possibly even a few weeks later this year, if you would like to, we could meet then.
Posted by: wfaulk

Re: Strip WAV headers from WAV-embedded MP3-files - 21/03/2003 12:43

Don't worry about it. It was a good reason to not do real work for a few. You can buy me drink if we ever meet in person.

Are you going to the Amersfoort meet? I'd very much like to be there, but my expected raise fell through (at least for the moment), so it's looking like I won't make it.

But if I do and you do, I expect a beer!
Posted by: smu

Re: Strip WAV headers from WAV-embedded MP3-files - 21/03/2003 13:13

Are you going to the Amersfoort meet?

Sure.

I'd very much like to be there,[...] But if I do and you do, I expect a beer!

Promised. And I really hope you can come.

cu,
sven