19

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.

VC.One
  • 12,230
  • 4
  • 21
  • 51
Android Team
  • 11,274
  • 2
  • 26
  • 46
  • Do you have a link or name to the (Android) FFmpeg build you're using? – VC.One Mar 28 '17 at 05: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 '17 at 18:15

2 Answers2

22

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
VC.One
  • 12,230
  • 4
  • 21
  • 51
  • 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. – Android Team Mar 29 '17 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 – Android Team Mar 29 '17 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 02 '17 at 05:24
  • for me 20MB mp3 converted to 3.6 MB file. thanks alot – saber tabatabaee yazdi May 13 '20 at 19:14
7

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"
coderofsalvation
  • 1,361
  • 12
  • 11