Search code examples
javalinuxffmpegmp3jave

JAVE (Java Audio Video Encoder) library exception only on Linux (CentOS 7)


I'm using JAVE (Java Audio Video Encoder) library and the developed application is on windows. On windows the conversion of an .mp3 file is working fine but when I deployed on linux (CentOS 7) an exception is thrown.

As I understand JAVE has also a wrapper around an ffmpeg executable.

Here is my code:

try {
        File source = new File(sourceFile);
        File target = new File(targetFile);

        final AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame");
        audio.setBitRate(88000);
        audio.setChannels(2);
        audio.setSamplingRate(44100);   

        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp3");
        attrs.setAudioAttributes(audio);

        Encoder encoder = new Encoder();
        encoder.encode(source, target, attrs);
} catch (EncoderException ex) {
    throw ex;
}

Exception:

...

Caused by: it.sauronsoftware.jave.EncoderException: Error while opening codec for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height
    at it.sauronsoftware.jave.Encoder.encode(Encoder.java:926)
    at it.sauronsoftware.jave.Encoder.encode(Encoder.java:713)
    at com.hft2.ejb.util.Mp3JaveEncoder.encode(Mp3JaveEncoder.java:36)
    ... 206 more

Update

Here is the official page: http://www.sauronsoftware.it/projects/jave/

Full exception log: https://jpst.it/1678l

Does anyone have any idea?


Solution

  • I've changed the bitRate value of the audioAttributes object from 88000 to 96000 based on Sampling rates documented on the following page: https://micropyramid.com/blog/understanding-audio-quality-bit-rate-sample-rate/

    Using the value of: 96000 as bit rate resolved my issue on linux environment. Very interesting that on windows worked fine with the value of 88000.

    Did some tests and here is the result:

    Linux supported bitRate values: 128000, 96000, 64000, 56000, 32000;
    Linux not supported bitRate values: 88000, 24000, 16000;
    

    Thanks for support!