java MP3等格式转换和压缩

依赖的jar: jave-1.0.2.jar
下载地址:http://www.sauronsoftware.it/projects/jave/jave-1.0.2.zip
示例:压缩MP3文件

package test;

import java.io.File;

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

public class TestCompressMp3 {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        testCompressMp3Samll();
    }

    public static void testCompressMp3Samll() throws Exception{
        Long t1 = System.currentTimeMillis();
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame");
        audio.setBitRate(64000);//设置比特率
        audio.setSamplingRate(44100);
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp3");//设置格式
        attrs.setAudioAttributes(audio);
//      attrs.setDuration(360f); // 设置截取的时长
        Encoder encoder = new Encoder();
        encoder.encode(new File("D:/test/1.mp3"), 
                new File("D:/test/target64.mp3"), attrs);
        Long t2= System.currentTimeMillis();
        System.out.println("消耗:"+(t2-t1)+"ms");
    }

}
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页