首页 > 其他分享 >啊

时间:2023-07-22 16:13:10浏览次数:28  
标签: String MultimediaObject encodingAttr startTime new audioStream

import ws.schild.jave.*;

public class AudioCutter {

public static void main(String[] args) throws Exception {
// 原始音频文件路径
String sourceAudio = "source.mp3";
// 截取后的音频文件路径
String targetAudio = "target.mp3";
// 开始时间(单位:毫秒)
long startTime = 5000;
// 结束时间(单位:毫秒)
long endTime = 10000;
// 创建音频编码属性对象
AudioAttributes audioAttr = new AudioAttributes();
EncodingAttributes encodingAttr = new EncodingAttributes();
encodingAttr.setAudioAttributes(audioAttr);
// 创建媒体对象
MultimediaObject multimediaObject = new MultimediaObject(new java.io.File(sourceAudio));
// 创建截取器
AudioStream audioStream = multimediaObject.getAudio();
audioStream.setStartTime(new Timecode(startTime, audioStream.getTimeBase()));
audioStream.setDuration(new Timecode(endTime - startTime, audioStream.getTimeBase()));
// 转换音频格式
Encoder encoder = new Encoder();
encoder.encode(new MultimediaObject(audioStream), new java.io.File(targetAudio), encodingAttr);
System.out.println("音频截取完成");
}
}

标签:,String,MultimediaObject,encodingAttr,startTime,new,audioStream
From: https://www.cnblogs.com/ENU7/p/17573518.html

相关文章