a-schild / jave2

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
GNU General Public License v3.0
1.28k stars 249 forks source link

different bitrate between windows and linux when convert wav to mp3 #192

Open jelly074100209 opened 2 years ago

jelly074100209 commented 2 years ago

Hi when i converted a wav file to mp3, the bitrate under windows is 80k, but under linux is 32k. after checking the file properties, found: windows mp3 format: MP3 32 Kbps VBR OFL linux mp3 format: MP3 80 Kbps CBR

which i confused, why i had set the bitrate, but the result is different?

public static boolean wavToMp3(String sourceWavFile, String targetMp3File, int bitrate, int channel, int sampleRate) { File source = new File(sourceWavFile); File target = new File(targetMp3File);

    AudioAttributes audioAttributes = new AudioAttributes();
    audioAttributes.setCodec("libmp3lame");
    audioAttributes.setBitRate(bitrate); // I set bitrate=80000
    audioAttributes.setChannels(channel);
    audioAttributes.setSamplingRate(sampleRate);

    EncodingAttributes encodingAttributes = new EncodingAttributes();
    encodingAttributes.setInputFormat("wav");
    encodingAttributes.setOutputFormat("mp3");
    encodingAttributes.setAudioAttributes(audioAttributes);

    Encoder encoder = new Encoder();
    try {
        encoder.encode(new MultimediaObject(source), target, encodingAttributes);
        return source.delete();
    } catch (Exception e) {
        log.error("convert failed: {}, source file: {}", e.getMessage(), sourceWavFile);
        return false;
    }
}
a-schild commented 2 years ago

What jave version are you using on windwows and on linux?

jelly074100209 commented 2 years ago

What jave version are you using on windwows and on linux?

ws.schild jave-core 3.2.0
    <dependency>
        <groupId>ws.schild</groupId>
        <artifactId>jave-nativebin-linux64</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>ws.schild</groupId>
        <artifactId>jave-nativebin-win64</artifactId>
        <version>3.2.0</version>
    </dependency>
jelly074100209 commented 2 years ago

I'm sorry, the format result shoule be: windows mp3 format: MP3 80 Kbps CBR linux mp3 format: MP3 32 Kbps VBR OFL