How to convert High bitrate MP3 to lower rate using FFmpeg

26,323

Solution 1

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

Solution 2

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"

Solution 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).

Share:
26,323

Related videos on Youtube

Mobile Team ADR-Flutter
Author by

Mobile Team ADR-Flutter

We are the Mobile Team @ WeblineIndia and over these years we have developed lots of Android apps for various domains like – Business, Social, Medical, News, Sports, Education, etc. We also have expertise in custom SDK development. Our main focus has always been to exceed client expectations and deliver easy to use technically strong apps. On the side, we also love contributing back to the community. We are always eager to contribute back to the community and so happy to help here to our developer community on any technical problems and discussions. We also love to contribute on TechNetExperts. Click here to know more about our Mobile App Development Services.

Updated on January 27, 2022

Comments

  • Mobile Team ADR-Flutter
    Mobile Team ADR-Flutter over 2 years

    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
      VC.One over 7 years
      Do you have a link or name to the (Android) FFmpeg build you're using?
    • VC.One
      VC.One over 7 years
      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...
    • Jake
      Jake over 2 years
      This appears to be unrelated to Android, and about ffmpeg in general. Suggest removing android tag and updating title.
  • Mobile Team ADR-Flutter
    Mobile Team ADR-Flutter about 7 years
    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.
  • Mobile Team ADR-Flutter
    Mobile Team ADR-Flutter about 7 years
    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
  • VC.One
    VC.One about 7 years
    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....
  • Arnaud Meuret
    Arnaud Meuret over 5 years
    The -ar achieved what I was expecting from -b:a
  • saber tabatabaee yazdi
    saber tabatabaee yazdi about 4 years
    for me 20MB mp3 converted to 3.6 MB file. thanks alot
  • Jake
    Jake over 2 years
    Error: "Could not find tag for codec h264 in stream #0, codec not currently supported in container". Clearly we need some way to tell ffmpeg that it's audio only. Any ideas?
  • Jake
    Jake over 2 years
    -map 0:0 seems to fix it. Why is that not the default?
  • VC.One
    VC.One over 2 years
    @Jake How to reproduce that error? MP3 is not a container so it can't have been from -i input.mp3.
  • Jake
    Jake over 2 years
    @VC.One it was a .m4a file.
  • VC.One
    VC.One over 2 years
    I can't reproduce your error message. This works okay ffmpeg -i test.m4a -c:a libmp3lame -qscale:a 5 test.mp3. I don't know why H264 video codec was mentioned by FFmpeg if you used an audio-only file (and not a renamed MP4)...
  • Jake
    Jake over 2 years
    ffmpeg -i input.m4a -b:a 80k output.m4a. Stream mapping: Stream #0:1 -> #0:0 (mjpeg (native) -> h264 (libx264)) Stream #0:0 -> #0:1 (aac (native) -> aac (native)). The mjpeg 'stream' I think is just cover art.