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

How to convert audio in ogg format to amr #216

Closed AdorableParker closed 2 years ago

AdorableParker commented 2 years ago

I am trying to convert an audio file in ogg format to amr, but when i do it prompts me Exception in thread "main" ws.schild.jave.EncoderException: Exit code of ffmpeg encoding run is 1 This is what I did:

fun ogg2amr() {
    val cacheFile = File("speak.ogg")
    val target = File("input.amr")

    val audio = AudioAttributes()
    audio.setCodec("libvo_amrwbenc")

    val attrs = EncodingAttributes()
    attrs.setOutputFormat("amr")
    attrs.setAudioAttributes(audio)

    Encoder().encode(MultimediaObject(cacheFile), target, attrs)
}
AdorableParker commented 2 years ago

The problem has been solved, the code is modified as follows:

fun ogg2amr() {
    val cacheFile = File("speak.ogg")
    val target = File("input.amr")

    val audio = AudioAttributes()
    audio.setCodec("libopencore_amrnb")
    audio.setChannels(1);
    audio.setSamplingRate(8000)

    val attrs = EncodingAttributes()
    attrs.setOutputFormat("amr")
    attrs.setAudioAttributes(audio)

    Encoder().encode(MultimediaObject(cacheFile), target, attrs)
}