Master Audio/Video Conversion with JAVE2: A Java FFmpeg Wrapper Guide

This article introduces JAVE2, a Java wrapper for FFmpeg that enables audio and video transcoding, explains installation requirements, shows how to integrate it via Maven/Gradle, provides practical code examples for format conversion and progress monitoring, and addresses common pitfalls such as missing native binaries.

Programmer DD
Programmer DD
Programmer DD
Master Audio/Video Conversion with JAVE2: A Java FFmpeg Wrapper Guide

What is JAVE2?

JAVE2 (Java Audio Video Encoder) is a Java wrapper around the FFmpeg project that allows developers to transcode audio and video files between formats, resize videos, adjust aspect ratios, and more.

JAVE2 is a small Java library that wraps FFmpeg into Java classes. It is based on Carlo Pelliccia's original work and has been updated with newer FFmpeg binaries.

Installation and Requirements

To use JAVE2, add the jave-1.0.jar file to your application classpath. JAVE runs on a Java Runtime Environment J2SE v1.4 or later.

How to Use JAVE2

GitHub repository: https://github.com/a-schild/jave2 . The project supports Java 8+ and a wide range of operating systems.

Supported OS + Requirements

Java 8+ is required; the library works on Windows, Linux, and macOS.

Maven / Gradle Integration

JAVE2 consists of two main components:

jave-core – platform‑independent Java code.

jave-nativebin – native binaries for each platform.

Example Maven dependency (replace with the latest version):

<dependency>
  <groupId>ws.schild</groupId>
  <artifactId>jave-all-deps</artifactId>
  <version>2.7.3</version>
</dependency>

For a specific platform, add the corresponding native binary dependency, e.g., for Windows 64‑bit:

<dependency>
  <groupId>ws.schild</groupId>
  <artifactId>jave-nativebin-win64</artifactId>
  <version>2.7.3</version>
</dependency>

Similarly, use jave-nativebin-linux64 for Linux 64‑bit and jave-nativebin-osx64 for macOS.

Practical Example: Convert AMR to MP3

public class ArmToMp3Test {
    private static Logger logger = LoggerFactory.getLogger(ArmToMp3Test.class);
    public static void main(String[] args) {
        try {
            File source = new File("D:\\tmp\\Java编程技术乐园.amr");
            File target = new File("D:\\tmp\\java编程技术乐园amrToMp3.mp3");
            AudioAttributes audio = new AudioAttributes();
            audio.setCodec("libmp3lame");
            audio.setBitRate(128000);
            audio.setChannels(2);
            audio.setSamplingRate(44100);
            EncodingAttributes attrs = new EncodingAttributes();
            attrs.setFormat("mp3");
            attrs.setAudioAttributes(audio);
            Encoder encoder = new Encoder();
            encoder.encode(new MultimediaObject(source), target, attrs);
        } catch (Exception ex) {
            logger.error("ArmToMp3Test#main exception", ex);
        }
    }
}

Advanced Usage: Progress Listener

Implement ws.schild.jave.EncoderProgressListener to receive callbacks during encoding.

public interface EncoderProgressListener {
    void sourceInfo(MultimediaInfo info);
    void progress(int permil);
    void message(String message);
}

Custom implementation example:

public class MyChanageEncoderProgressListener implements EncoderProgressListener {
    private static Logger logger = LoggerFactory.getLogger(MyChanageEncoderProgressListener.class);
    @Override
    public void sourceInfo(MultimediaInfo info) {
        long ls = info.getDuration() / 1000;
        int hour = (int) (ls / 3600);
        int minute = (int) ((ls % 3600) / 60);
        int second = (int) (ls - hour * 3600 - minute * 60);
        String length = hour + "时" + minute + "分" + second + "秒";
        logger.info("sourceInfo -> {}", info);
        logger.info("length -> {}", length);
    }
    @Override
    public void progress(int permil) {
        logger.info("progress -> {}", permil);
    }
    @Override
    public void message(String message) {
        logger.info("message -> {}", message);
    }
}

Use the listener when encoding:

Encoder encoder = new Encoder();
encoder.encode(new MultimediaObject(source), target, attrs, new MyChanageEncoderProgressListener());

Common Issue: Missing Native Binary

Cannot run program "C:\...\ffmpeg-amd64-2.7.3.exe": CreateProcess error=2, The system cannot find the file specified.

This occurs when the jave-nativebin-win64 dependency is not added. Adding the correct native binary ensures the FFmpeg executable is extracted to a temporary folder and executed.

Summary

Although the original JAVE project is no longer maintained, JAVE2 provides a powerful, actively updated solution for audio and video processing in Java, supporting Maven/Gradle integration, multiple operating systems, and advanced features such as progress monitoring.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavamavenffmpegAudio Video EncodingJAVE2Progress Listener
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.