27

We want to convert 320kbps mp3 file to 128kbps mp3 so currently we are using below ffmpeg command but its not working.

ffmpeg -i input.mp3 -codec:a libmp3lame -qscale:a 5 output.mp3

Result:-the output bitrate same as input mp3.

And we are following the FFmpeg Encoding guideline for that here is the link :- https://trac.ffmpeg.org/wiki/Encode/MP3

so please suggest any solution.

3
  • Do you have a link or name to the (Android) FFmpeg build you're using?
    – VC.One
    Mar 28, 2017 at 5:09
  • After years of FFmpeg usage I arrogantly didn't need to check how to set audio bitrate - I can just tell you... After reading your link now I see you were looking at Variable BitRate (VBR) settings where -qscale:a 5 does aim for average bitrate of around 130kbps. Anycase your question sounds like really you want a Constant BitRate (CBR) of 128kbps. PS: I wanted to know your FFmpeg build because you can't input 320kbps with setting -qscale:a 5 and get output of exact same 320kbps. What's wrong with it? I want to check...
    – VC.One
    Mar 28, 2017 at 18:15
  • 1
    This appears to be unrelated to Android, and about ffmpeg in general. Suggest removing android tag and updating title.
    – Jake
    Dec 22, 2021 at 0:26

3 Answers 3

35

I tried your shown command (tested on Windows / commandline) :

ffmpeg -i input.mp3 -codec:a libmp3lame -qscale:a 5 output.mp3

Result : It works for me. However the -qscale:a 5 makes FFmpeg decide on an average bitrate for you. With one (320k) MP3 file I got it giving a close convert of 134kbps. This is expected since :

lame option   Average kbit/s  Bitrate range kbit/s    ffmpeg option
   -V 5             130           120-150                -q:a 5

Solution :
Instead of making the internal mp3 frames hold different bitrates (that vary to acommodate the "current" perceived audio, eg: think "silent" parts using smaller rate of bits/bytes compared to "busy" audio parts), so just set a constant bitrate of 128kbps as you need.

I would just set it to constant 128kbps manually and explicitly with :

ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 128k output.mp3
10
  • Thanks for replying but we have tried your given command but in the output log audio bitrates is 320 kbps after conversion.so and I have tried using android FFmpegAndroid library.so its not working for us.
    – user4571931
    Mar 29, 2017 at 12:16
  • Below is the log.but the bitrates of mp3 is 320Kbps Output #0, mp3, to '/storage/AUD_1490697495080.mp3': Metadata: TIT2 :Jab Tak TALB :MS Dhoni TPE1 :Armaan TSSE :Lavf56.4.101 Stream #0:1: Audio:mp3,44100 Hz,stereo,320 kb/s frame=1 fps=0.0 q=0.0 Lsize=1470kB time=00:00:15.00 bitrate=802.2kbits/s
    – user4571931
    Mar 29, 2017 at 12:25
  • 1
    So output file AUD_1490697495080.mp3 is a different name to the input file name, right? I mean afterwards you have two separate files that are both 320k, is that correct? I'm trying to visualize your issue and if YES about two files @ 320k then your result could only happen if used -codec:a copy instead of -codec:a libmp3lame... This is why I need to know your exact FFmpeg build (got a link?) to test exact same thing because maybe you have a buggy version....
    – VC.One
    Apr 2, 2017 at 5:24
  • 2
    for me 20MB mp3 converted to 3.6 MB file. thanks alot May 13, 2020 at 19:14
  • 1
    -map 0:0 seems to fix it. Why is that not the default?
    – Jake
    Dec 22, 2021 at 0:13
9

I use this shellscript in order to not visit this stackoverflow-page over and over again :)

#!/bin/bash
[[ ! -n $1 ]] && { 
    echo "Usage: mp3convert <input.mp3> <output.mp3> <bitrate:56/96/128/256> <channels> <samplerate>"
    exit 0
}
set -x # print next command
ffmpeg -i "$1" -codec:a libmp3lame -b:a "$3"k -ac "$4" -ar $5 "$2"
1
  • 1
    The -ar achieved what I was expecting from -b:a Nov 22, 2018 at 11:25
3

Make sure your version of FFmpeg has libmp3lame enabled. The selected answer didn't work for me, but this did:

ffmpeg -v debug -i "input.mp3" -c:a libmp3lame \
   -b:a 128k -ac 2 -ar 44100 -vn "output.mp3"

-ac 2 - output has 2 (stereo) audio channels -ar 44100 - sample rate of 44100Hz, which is ideal for high quality music.

Although, in 2022 I wouldn't recommend converting to 128kbps since storage space is much more cheap and abundant nowadays.

I think -b:a 192k strikes the best balance between compression and quality for most people (unless you're an audiophile with $1000 headphones, and even then you'd be better off using FLAC anyways).

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.