I am using xugglu in java in order to switch the bitrate of the input MP3 file, storing it in a output file. I took one example I found on the net the loads the file to a reader and adds a writer as a listener. Does anyone know how can I then modify the bitrate?
Here's the code I've been using:
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import org.slf4j.LoggerFactory;
public class TranscodingExample {
private static final String inputFilename = "/home/user/Desktop/file_changed.mp3";
private static final String outputFilename = "/home/user/Desktop/file_changed.flv";
public static void main(String[] args) {
// create a media reader
IMediaReader mediaReader =
ToolFactory.makeReader(inputFilename);
// create a media writer
IMediaWriter mediaWriter =
ToolFactory.makeWriter(outputFilename, mediaReader);
// add a writer to the reader, to create the output file
mediaReader.addListener(mediaWriter);
// create a media viewer with stats enabled
IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
// add a viewer to the reader, to see the decoded media
mediaReader.addListener(mediaViewer);
// read and decode packets from the source file and
// and dispatch decoded audio and video to the writer
while (mediaReader.readPacket() == null) ;
}
}
EDIT-1:
I couldn't really get around this one, so I just used a linux command doing that inside the Java app. You can find a reference to the code here. The command I used was:
ffmpeg -i in.mp3 -b 112k out.mp3
It converts the mp3 to a new one of bitrate equal to 112k.
Take a look at IAudioResampler:
Used to resample IAudioSamples to different sample rates or number of channels.