Java - Convert ogg to mp3
Asked Answered
L

1

0

I'm writing a Java program and I'd like to convert a ogg file into mp3 file.
I've spend a lot of time trying to find a good library to do that, but without success for the moment.

I think I'll need a ogg decoder (jorbis ?) and a mp3 encoder (lameOnJ ?).
Moreover, once the conversion is done, I need to set some tags in the file (artist/track tag, etc).

This is a windows and OS X app.
Could you give me any hint about how to process, with examples if possible.

Thanks

Lasky answered 9/8, 2012 at 12:38 Comment(3)
Whats your specific problem? There are libraries to do each of the steps available, and you already figured out candidates to use. You just need to write the glue code to wire them together.Acquit
Well I'm fairly new to Java and have difficulties to find good examples to write this glue code.Lasky
Nobody will write it for you (unless you pay them). And there will be most likely no examples that do what you need. But you can google for the partial solution examples for each step (divide and conquer!). Start from the beginning with the first step, decoding the ogg file. When you have that, extend it to feed the decoded data into the encoder. And so on...Acquit
T
0

You have lots of choices, and it depends on how much effort you want to put in, and what constraints you have regarding the execution platform.

Many developers would simply make System.exec() calls to external decode/encode/label executables, writing the intermediate files to disk. This is slightly clunky, but once it's set up properly, it works.

A more sophisticated option is to use libraries such as the ones you've found. You can still use the filesystem to temporarily store the uncompressed version.

You can, however, avoid storing the intermediate step -- and maybe make it faster -- by pipelining. You need to feed the output of the decoder as the input of the encoder, and set them both going.

The details of this depends on the API. If you're lucky, they can work with chunks, and you may be able to manage them in a single thread.

If they work with streams, you might need to get your hands dirty and work with threads. One thread for the encoder, one for the decoder.

Transferase answered 9/8, 2012 at 13:27 Comment(2)
@Acquit say one API has a synchronous method OggDecoder.decode(InputStream in, OutputStream out) and the other has Mp3Encoder.encode(InputStream in, OutputStream out). If you want to pipe one into the other, you will need threads -- or store the intermediate format somewhere.Transferase
Ah I hadn't thought far enough. I see now what you meant.Acquit

© 2022 - 2024 — McMap. All rights reserved.