Codec and setting for lowest bitrate ffmpeg output
AAC or MP3 are not the best choice of codecs for ultra-low bandwidth transmissions. Use a proper speech codec with higher efficiency.
Opus is the best option. It is available in FFmpeg through libopus
. In fact, Opus is not just made for speech; it offers hybrid encoding for both speech and music.
Example:
ffmpeg -i <input> -c:a libopus -ac 1 -ar 16000 -b:a 8K -vbr constrained out.opus
Here, -ac
sets the output to mono, -ar
sets the sampling rate to 16 kHz, and -b:a
sets the bitrate to 8 kBit/s. The constrained variable bitrate mode is used here. In principle, it's not strictly necessary to downsample and downmix to mono with ffmpeg
, as that is something libopus
will do on its own to reach the specified bitrate target.
Some further recommendations are given here. Note that with Opus, 6–8 kBit/s is usable range for (mono, lower sample rate) speech, but not for music.
You'll find an interesting comparison of different codecs and their bitrate/quality curve on the Opus website:
I should add that this figure is an indication only; it's compiled from different test results and anecdotal knowledge.
Related videos on Youtube
Comments
-
peiman F. over 1 year
I need to convert my input audio file to the lowest possible size to transfer it over a radio transmitter.
Now with the AAC codec and MP3 format I used 8kbps for bit rate, 16 kHz for sampling rate and 1 channel, and my output data is about 3kb per second.
But when I change the sample rate to 8 kHz or a lower bit rate, I get an error saying that the codec does not support this setting.
Is there a setting to get lower rate for the output file?
P.S: Because I'm working on Android, it's hard to install codecs, so I must use the ffmpeg default codecs.
Update:
i used opus command line now this is my command:
ffmpeg -i a.mp3 -vn -c:a libopus -ac 1 -ar 8000 -b:a 500 -vbr constrained -compression_level 0 -application lowdelay output22.mkv
and the result is
Input #0, mp3, from 'a.mp3': Metadata: title : Salam (myahangha.ir) artist : Sogand album : Javooni comment : ..:: myahangha.ir ::.. genre : 2019 date : 2019 Duration: 00:03:15.24, start: 0.000000, bitrate: 324 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 500x500 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc Metadata: title : Radio Javan - Javooni.jpg comment : Other Stream mapping: Stream #0:0 -> #0:0 (mp3 (mp3float) -> opus (libopus)) Press [q] to stop, [?] for help [libopus @ 0000028b84d9e200] Bitrate 500 is extremely low, maybe you mean 500k The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s Output #0, matroska, to 'output24.mkv': Metadata: title : Salam (myahangha.ir) artist : Sogand album : Javooni comment : ..:: myahangha.ir ::.. genre : 2019 date : 2019 encoder : Lavf58.27.102 Stream #0:0: Audio: opus (libopus) ([255][255][255][255] / 0xFFFFFFFF), 8000 Hz, mono, flt, 0 kb/s Metadata: encoder : Lavc58.51.100 libopus size= 116kB time=00:03:15.25 bitrate= 4.9kbits/s speed= 396x video:0kB audio:57kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 103.282921%
it seems opus dont accept bit rates lower then 4.9kbps :(
-
slhck about 5 yearsI've edited your post to add "kHz" to sampling rate. I assumed you meant that. Or do you mean bits per sample?
-
Attie about 5 yearsAlso, could you clarify if you mean "3 kb/s (kilobits / sec)", or "3 kB/s (kiloBytes / sec)"
-
slhck about 5 yearsWho is @roozgar and why is he or she clarifiying your post for you?
-
peiman F. about 5 yearsno problem, we are working together on this project :)
-
slhck about 5 yearsI see. Next time when asking about ffmpeg, please include the specific command(s) that you were trying and any command-line output that you got (including errors).
-
peiman F. about 5 years@slhck i added the command and result , thank you
-
slhck about 5 years4.9 kBit/s is really not much. You should be looking into AMR-NB.
-
-
peiman F. about 5 yearsthank you, i will try
HE-AAC v2
orlibopus
but how about if i use default ffmpeg codecs ?! -
slhck about 5 yearsPlease read my answer again: you should not use AAC, but Opus. There's no proper Opus support for lower bitrates built into ffmpeg. Same for other speech codecs like AMR-NB. You need to compile ffmpeg with these options. It's possible to do that for Android. See: github.com/tanersener/mobile-ffmpeg
-
peiman F. about 5 yearsthank you,but is the output of this coded is
.opus
and it need a specific player to play sounds؟ -
slhck about 5 yearsIt needs a player that can decode Opus, yes.