views:

408

answers:

3

i want to achieve mp3 compression.. it means i want to convert a 256kbps mp3 file into a 128 or even 64kbps mp3 file using java programming language..

is it possible using JLayer..? how do i do it..?

A code snippet would be useful.

Thanks in advance..!!

+1  A: 

To convert an MP3 file to a file of lower bitrate, you must decode and re-encode the file, so you need an MP3 decoder and an MP3 encoder.

You'll have to find a Java library for de/encoding MP3. One option would be LameOnJ. It's a wrapper for the "lame" MP3 encoder, and uses a platform-specific binary/DLL.

There might also be a pure Java solution, but I don't know any.

See also http://stackoverflow.com/questions/316612/mp3-encoding-in-java

sleske
cant i use JLayer to encode and decode....?
veenit33
Sure looks like you can, have you tried?
Nick Veys
+1  A: 

Decoding MP3 is straightforward. However, encoding MP3 is fraught with patents, licenses, and general legal mayhem. LAME is one possibility to adapt, but it too suffers from potential litigation encumbrances. It is also known to be poor at lower bit rates. It is written in C, so you'd have to do translation.

wallyk
You could use Java Native Access (JNA). It's a fairly easy way to access C libraries from Java. And by "fairly easy" I mean you just write an Interface and include the jna.jar file.
Greg Smith
@Greg: Actually, LameOnJ (see my answer) is precisely a Java wrapper for the "lame" library, so no need to use JNA directly (though it would be possible).
sleske
It's a common mistake to believe that MP3 encoding is "straightforward". License fees are due to the patent consortium both for decoders and encoders. The basic rates start at US$ 0.75 for a software decoder and US$ 2.50 for an encoder (decoder license included).
jarnbjo
+1  A: 

JLayer is decoding only. There is no 100% java solution for encoding. LAME is officially distributed in source code only, so if you want to avoid patent infrigement, you can not distribute LAME binaries with your program without buying a license.

tulskiy