Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How convert High bitrate mp3 to lower rate using ffmpeg in android

Tags:

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.

like image 464
Android Team Avatar asked Mar 22 '17 09:03

Android Team


2 Answers

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
like image 126
VC.One Avatar answered Oct 24 '22 18:10

VC.One


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"
like image 21
coderofsalvation Avatar answered Oct 24 '22 19:10

coderofsalvation