jave-1.0.2.jar 下载 。 安装到maven使用
参考: https://blog.csdn.net/weixin_43064185/article/details/121823276
下载jar包到本地
mvn install:install-file -Dfile=D:\repository\jave-1.0.2\jave-1.0.2.jar -DgroupId=wg -DartifactId=jave -Dversion=1.0.2 -Dpackaging=jar
maven中引入:
<dependency>
<groupId>wg</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
</dependency>
public static void main(String[] args) {
try {
String sourcePath = "C:\\Users\\hezha\\Desktop\\合成\\Video_2023-11-14_221008.wmv";
String targetPath = "C:\\Users\\hezha\\Desktop\\合成\\Video_2023-11-14_221008.mp4";
File source = new File(sourcePath);
File target = new File(targetPath);
// 创建转换器
Encoder encoder = new Encoder();
// 创建目标文件的编码格式
EncodingAttributes attributes = new EncodingAttributes();
attributes.setFormat("mp4");
// 创建音频属性
AudioAttributes audioAttributes = new AudioAttributes();
audioAttributes.setCodec("aac"); // 设置音频编码器
audioAttributes.setBitRate(256000); // 设置音频比特率
audioAttributes.setChannels(2); // 设置音频通道数
audioAttributes.setSamplingRate(44100); // 设置音频采样率
attributes.setAudioAttributes(audioAttributes);
// 创建视频属性
VideoAttributes videoAttributes = new VideoAttributes();
videoAttributes.setCodec("mpeg4"); // 设置视频编码器
videoAttributes.setBitRate(8000000); // 设置视频比特率,越大越高清
videoAttributes.setFrameRate(60); // 设置视频帧率
attributes.setVideoAttributes(videoAttributes);
// 开始转换
encoder.encode(new File(sourcePath), new File(targetPath), attributes);
System.out.println("转换完成");
} catch (EncoderException e) {
e.printStackTrace();
}
}