Java 中的 MP3 编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/316612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MP3 Encoding in Java
提问by M.N
I need an OpenSource API in Java, which can encode *.wav and *.au formats to MP3 and vice-versa.
我需要一个 Java 中的开源 API,它可以将 *.wav 和 *.au 格式编码为 MP3,反之亦然。
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.
我已经评估了 Java Sound API 和LameOnJ,但它们分别不符合我的要求并且不稳定。请推荐一款免费且独立于平台的软件。
采纳答案by jamesh
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.
然而,您可能没有足够的答案,因为 MP3 格式要求解码器/编码器的作者从弗劳恩霍夫研究所获得许可。
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.
我认为 LAME 库是从一个不尊重这些 IP 问题的国家/地区分发的,但要走到这一步需要大量的合法黑客。
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.
对于任何其他库——例如用 Java 编写的库,作者需要获得类似的许可。如果成本是一个问题——例如在一个开源项目中,那么这足以阻碍开始。
For more details see this wikipedia article.
有关更多详细信息,请参阅这篇维基百科文章。
If LAME4J is not stable enough for you, then I'm afraid your options are probably:
如果 LAME4J 对您来说不够稳定,那么恐怕您的选择可能是:
- 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.
- 等待 Sun 许可核心 JRE 的格式。这个,我相信他们最近已经完成了,但我不知道任何发布日期(可能与 JavaFX 有关)
- 在 Java 中实现你自己的,并支付许可证。我也不喜欢这个。
- 通过 JNA 或 SWIG 将您自己的 Java 包装器写入 LAME
- 为 Lame4J 做出贡献。
- 选择另一种格式。OGG 和 FLAC 都不错,支持也比较好。
回答by Aaron Digulla
Use the Process APIto invoke SoX
使用Process API调用SoX
SoX comes with source or as precompiled binaries for Windows and Mac.
SoX 附带源代码或作为 Windows 和 Mac 的预编译二进制文件。
回答by Serghei Burtsev
The LAME4J uses the free but time-limited license and the unlimited license will cost you some money.
LAME4J 使用免费但有时间限制的许可证,无限制许可证将花费您一些钱。
I've found the Lamejb libraryon the SourceForge, which requires only the lame binaries and works well without any additional licensing.
我在 SourceForge 上找到了Lamejb 库,它只需要蹩脚的二进制文件,并且无需任何额外许可即可运行良好。
回答by kenchis
If you are searching a pure java version of lame, check out these sources: http://jsidplay2.cvs.sourceforge.net/viewvc/jsidplay2/jump3r/
如果您正在搜索 lame 的纯 Java 版本,请查看以下来源:http: //jsidplay2.cvs.sourceforge.net/viewvc/jsidplay2/jump3r/
回答by HafkensitE
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
已经有一段时间了,但是 Oracle/Sun 已经发布了对 JMF 的 MP3 支持。可以从以下网址下载:http: //www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
Adding it to the classpath will enable playback via the AudioSystem api.
将它添加到类路径将通过 AudioSystem api 启用播放。
回答by Guss
The Jave2 projectis Java library that wraps FFMPEG and provides most of its functionality*through a rather useful Java API.
该Jave2项目是Java库,包装FFMPEG,并提供其大部分功能*通过一个相当有用的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.
- 有用的 Java API,功能强大且相当简单。
- FFMPEG 二进制文件已捆绑在其中,因此您无需在系统上管理 FFMPEG 安装。
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**.
- 不支持流数据:您必须处理临时文件:每次转换首先将所有内容存储在系统上的某些文件中,让 FFMPEG 为您创建新文件,然后读取它们。这不是 FFMPEG 的缺陷,更多的是 Java 中的一个问题,其中很难将数据流式传输到外部进程**。
*) 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.
**) 在 Java 中,启动一个进程并连接到它的标准输出和输入是可能的,但并不舒服,并且使用命名管道(用于将 AV 传输到/从 FFMPEG 的 BKM)几乎是不可能的,即使你设法做到了那个,Jave2 不能很好地发挥作用。我有一套基于 JNA 的工具来解决这些问题,如果有人感兴趣的话 - 我可以分享。