title: change bitrate of mp3
body: <p>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?</p>
  
  <p>Here's the code I've been using:</p>
  
  <pre><code>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) ;
  
  }
  }
  </code></pre>
  
  <p>EDIT-1:</p>
  
  <p>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 <a href="http://singztechmusings.wordpress.com/2011/06/21/getting-started-with-javas-processbuilder-a-sample-utility-class-to-interact-with-linux-from-java-program/" rel="nofollow">here</a>. The command I used was:</p>
  
  <pre><code>ffmpeg -i in.mp3 -b 112k out.mp3
  </code></pre>
  
  <p>It converts the mp3 to a new one of bitrate equal to 112k.</p>