Java - Convert ogg to mp3

故事扮演 提交于 2019-12-20 06:00:59

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/11883659/java-convert-ogg-to-mp3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!