Compress mp3 files in java

How to compress MP3 files in Java

Recently I was working on a personal project. It needed to compress MP3 files for instance from 320KB bitrate to 128KB bitrate. After checking out some Java library that was really interesting in their own, I found JAVE library more useful to compress MP3 files. Now I publish how did I done my project with this library.

What is JAVE library

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project. Developers can take take advantage of JAVE to transcode audio and video files from a format to another. In example you can transcode an AVI file to a MPEG one, you can change a DivX video stream into a (youtube like) Flash FLV one, you can convert a WAV audio file to a MP3 or a Ogg Vorbis one, you can separate and transcode audio and video tracks, you can resize videos, changing their sizes and proportions and so on. Many other formats, containers and operations are supported by JAVE.


JAVE Requirements

JAVE requires a J2SE environment 1.4 or later and a Windows or Linux OS on a i386 / 32 bit hardware architecture. JAVE can also be easily ported to other OS and hardware configurations, see the JAVE manual for details.


JAVE License

This package is Free Software and it is licensed under GPL (you will find a copy of the license bundled into the downloadable software distribution).


Download JAVE library

you can download this library from


Java Code to compress MP3 files with JAVE

Import following classes in your Java project

import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncodingAttributes;

Now this code Convert Source.mp3 to target MP3 with 128KB bitrate

AudioAttributes audio = new AudioAttributes();
EncodingAttributes attrs = new EncodingAttributes();
attrs.setDuration(360); // 360 Seconds
Encoder encoder = new Encoder();
encoder.encode(“source.mp3”, “target.mp3”, attrs);


I hope this article helped you!

Published by

Milad Rahimi

I’m a software engineer with some big targets, I love what I do and nothing else matters…

Leave a Reply

Your email address will not be published. Required fields are marked *