bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.53k stars 1.58k forks source link

How to set the audio quality when convert m4a to mp3? #2072

Closed Mhuang77 closed 1 year ago

Mhuang77 commented 1 year ago

How to use the JavaCV API to set the audio quality option, which equals to the "-q:a 0" option in ffmpeg command? The FFmpeg command is like this:

ffmpeg -i output.m4a -q:a 0 tmp.mp3

I tried the FFmpegFrameRecorder class and wrote the " recorder.setOption("-q:a", "0")" in my code, but it does not work the code snippet like this:

        try (FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(baos,1);) {
            recorder.setFormat("mp3");
            recorder.setOption("q:a", "0");
//            recorder.setAudioQuality(0);  also not work 
            recorder.start();
}

FFmpeg MP3 Encoding Guide ref : https://trac.ffmpeg.org/wiki/Encode/MP3#:~:text=Control%20quality%20with%20%2Dqscale%3Aa,produces%20an%20%22acceptable%22%20quality.

saudet commented 1 year ago

That's what setAudioQuality() is for: http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/FrameRecorder.html#getAudioQuality--

Mhuang77 commented 1 year ago

That's what setAudioQuality() is for: http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/FrameRecorder.html#getAudioQuality--

thx~