JAVE(Java Audio Video Encoder)是ffmpeg项目的一个Java封装。可以利用JAVE在不同的视频与音频格式之间相互转换。比如能够将AVI文件转换成MPEG格式的文件,分离和转换视频与音频轨道,压缩视频,改变大小和比例。
public boolean compressFile(String sourcePath, String targetPath) {
File source = new File(sourcePath);
File target = new File(targetPath);
try{
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(87000));
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(48000));
VideoAttributes video = new VideoAttributes();
video.setCodec("mpeg4");
video.setBitRate(new Integer(12500000));
video.setFrameRate(new Integer(14));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp4");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
if(source.exists()){
source.delete();
}
return true;
}catch (EncoderException e){
e.printStackTrace();
logger.error("压缩失败");
return false;
}
}
参考地址:https://blog.csdn.net/qllinhongyu/article/details/29817297
jar下载链接地址:https://download.csdn.net/download/hiqingtian/10638786
————————————————
版权声明:本文为CSDN博主「阶前梧桐已秋声」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hiqingtian/article/details/82260803