M.N
M.N

Reputation: 11078

MP3 Encoding in Java

I need an OpenSource API in Java, which can encode *.wav and *.au formats to MP3 and vice-versa.

I have evaluated Java Sound API and LameOnJ, but they do not meet my requirements and are not stable, respectively. Please suggest one that is free and platform independent.

Upvotes: 10

Views: 26357

Answers (6)

Guss
Guss

Reputation: 32414

The Jave2 project is Java library that wraps FFMPEG and provides most of its functionality* through a rather useful Java API.

Pros:

  • Useful Java API that is powerful and rather simple.
  • FFMPEG binary is bundled in, so you don't have to manage an FFMPEG installation on your system.

Cons:

  • Does not support streaming data: you have to work through temporary files: every conversion starts by storing all the content in some files on the system, getting FFMPEG to create new files for you, then reading them. This is not a deficiency in FFMPEG, more of a problem in Java where it is very hard to stream data to external processes**.

*) specifically around format conversion - the filter functionality is mostly not represented.

**) In Java, launching a process and connecting to its standard output and input is possible but not comfortable, and using named pipes (the BKM for piping AV to/from FFMPEG) is almost impossible, and even if you do manage to do that, Jave2 doesn't play well with that. I have a set of tools to workaround these problems, based on JNA, if anyone is intersted - I can share.

Upvotes: 0

HafkensitE
HafkensitE

Reputation: 71

Is has been some time, but Oracle/Sun has released MP3 support for JMF. This can be downloaded from the following url: http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html

Adding it to the classpath will enable playback via the AudioSystem api.

Upvotes: 4

kenchis
kenchis

Reputation: 29

If you are searching a pure java version of lame, check out these sources: http://jsidplay2.cvs.sourceforge.net/viewvc/jsidplay2/jump3r/

Upvotes: 1

Serghei Burtsev
Serghei Burtsev

Reputation: 46

The LAME4J uses the free but time-limited license and the unlimited license will cost you some money.

I've found the Lamejb library on the SourceForge, which requires only the lame binaries and works well without any additional licensing.

Upvotes: 2

jamesh
jamesh

Reputation: 20111

There may not be an adequate answer for you, yet, as the MP3 format requires the authors of decoder/encoders to obtain a license from the Fraunhofer Institute.

I think the the LAME library is distributed from a country that does not respect these IP issues, but it took a considerably amount of legal hackery to get this far.

For any other libraries - for example one written in Java, the authors need to get a similar license. Where cost is an issue - e.g. in an Open Source project, then this is enough of a disincentive to starting.

For more details see this wikipedia article.

If LAME4J is not stable enough for you, then I'm afraid your options are probably:

  • wait for Sun to license the format for the core JRE. This, I believe they have done recently, but I don't know of any release dates (perhaps to do with JavaFX)
  • implement your own in Java, and pay the license. I wouldn't fancy this one, either.
  • write your own Java wrapper to LAME, via JNA, or SWIG
  • contribute to Lame4J.
  • pick another format. OGG and FLAC are quite good, and relatively well supported.

Upvotes: 6

Aaron Digulla
Aaron Digulla

Reputation: 328860

Use the Process API to invoke SoX

SoX comes with source or as precompiled binaries for Windows and Mac.

Upvotes: 1

Related Questions