This tool is mainly used to convert the AMR to MP3 format for playing in the audio tag of HTML5.
Linux, Windows and Mac is all supported.
Based on a well known project, named JAVE which relies on ffmpeg, this tool can be used to all ffmpeg supported format conversion. See JAVE official documentation for details.
<dependency>
<groupId>com.github.dadiyang</groupId>
<artifactId>jave</artifactId>
<version>1.0.6</version>
</dependency>
Just 3 lines, JAVE make it extraordinary easy.
public void amrToMp3() {
File source = new File("target/test-classes/material/testAudio.amr");
File target = new File("testAudio.mp3");
AudioUtils.amrToMp3(source, target);
}
- Determine the current running environment when initializing and copy the corresponding ffmpeg executable file in classpath:bin directory to a temporary directory
- Invoke Runtime.getRuntime().exec(cmd) to execute ffmpeg's transcode command according to the format and configuration.
Ffmpeg is dependent on runtime platform, and JAVE project encapsulation the ffmpeg, it make ffmpeg has cross-platform features by the above mechanism. However, the old JAVE project has the following problems:
- It's too old. The latest time they release it was 2009. The ffmpeg it involved was outdated and didn't work in many conditions.
- EncoderException: Stream mapping somethings occur.
- It didn't publish to Maven Central Repository. Besides, JAVE itself is not a maven project.
- Mac was not supported.
Therefore, I created this project to solve the above problems.
- This is a maven project and has published to Maven Central Repository.
- The ffmpeg was updated and verified. (The project provided an unit test to easily verified)
- Avoid the EncoderException: Stream mapping.
- Linux, Windows and Mac is all supported.
Set System.setProperty("ffmpeg.home", "your ffmpeg executable file's path")
to specify your own ffmpeg executable when the provided one doesn't match your runtime.
eg. System.setProperty("ffmpeg.home", "/usr/local/bin/")
JAVE project is open source following GPL License, and this new JAVE project is modified and enhanced on the basis of JAVE, hence GPL License is adopted.