ken
ken

Reputation: 5086

How do I convert an audio stream to MP3 using Java?

Is it possible using Java to convert a real time audio stream from the mixer to MP3?

Upvotes: 4

Views: 12359

Answers (6)

Art Clarke
Art Clarke

Reputation: 2505

Use Xuggler to do it. It's free, and open source (LGPL), and uses libmp3lame under the covers. And the MediaTool API in Xuggler gives lots of examples of how to use it:

Upvotes: 2

krishnakumar
krishnakumar

Reputation: 173

try using Ring buffer to encode the raw audio buffer in fly.

Upvotes: -1

Aaron Digulla
Aaron Digulla

Reputation: 328556

Create a new process in Java and write the stream to the stdin of to a tool like SoX to have it convert the audio data to MP3 on the fly.

Upvotes: 0

PhiLho
PhiLho

Reputation: 41132

Lame is indeed the de facto standard on MP3 encoding, partly because of its high quality (encoding MP3 is hard to do right... and it is a subjective art), partly because of legal issues (MP3 is a patented technique, AFAIK, that's why you get Lame binaries from a limited number of sites, most of them in countries where these legal issues are less (or not) enforced).

The LAMEOnJ project found by VonC seems to use a non-free JNI implementation, but I suppose you can do your own binding with JNI or even JNA, particularly if you target a precise system.

Upvotes: 1

Bork Blatt
Bork Blatt

Reputation: 3368

As to the first question - is it possible, the only limitation I can see would be processor speed. If the algorithm you are using and your processor are both fast enough, there is no reason why it wouldn't be possible.

I know this isn't Java source, but it may get you on the right track - try looking at the Lame MP3 Encoder.

As far as I know all MP3 conversion algorithms work chunk by chunk. They don't need to read the whole WAV file to begin conversion, but they convert on the fly.

Upvotes: 0

VonC
VonC

Reputation: 1323553

May be you could use LAMEOnJ, which is a 100% Java API wrapping the standard LAME API (LAME being a MP3 encoder).

I am not sure however it would encode "chunk by chunk"...

Upvotes: 4

Related Questions