java 压缩mp3 比特率

下载:Xuggle_study(含xuggle jar).rar

http://download.csdn.net/detail/shuzheng5201314/8711543

 

用.zip打开jar完成到libxuggle.dll(linux为.so)文件拷贝到你的jdk bin目录下

 

public void convertToMP3(File input, File output, int kbps) { //modify on your convenience
    // create a media reader
    IMediaReader mediaReader = ToolFactory.makeReader(input.getPath());

    // create a media writer
    IMediaWriter mediaWriter = ToolFactory.makeWriter(output.getPath(), mediaReader);

    // add a writer to the reader, to create the output file
    mediaReader.addListener(mediaWriter);

    // add a IMediaListner to the writer to change bit rate
    mediaWriter.addListener(new MediaListenerAdapter() {
        @Override
        public void onAddStream(IAddStreamEvent event) {
            IStreamCoder streamCoder = event.getSource().getContainer().getStream(event.getStreamIndex()).getStreamCoder();
            streamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, false);
            streamCoder.setBitRate(kbps);
            streamCoder.setBitRateTolerance(0);
            }
        });

    // read and decode packets from the source file and
    // and dispatch decoded audio and video to the writer
    while (mediaReader.readPacket() == null);
}

 kbps = 64 * 1000

你可能感兴趣的:(java 压缩mp3 比特率)