步骤 2 : 代码
需要注意几点
1. 运行需要2个jar包 commons-logging-1.2.jar jave-2.0.jar 2. 需要用到 ffmpeg-x86.exe 以上3件都打包在了 jar-ffmpeg-x86.exe.rar,在相关下载区可以下载 3. 重写FFMPEGLocator的getFFMPEGExecutablePath方法,提供ffmpeg-x86.exe 程序的位置,我是放在D:\\project\\test\\ffmpeg-x86.exe,你可以放在希望的地方 import java.io.File;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.FFMPEGLocator;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.MultimediaInfo;
public class MP4Util {
public static void main(String[] args) throws InputFormatException, EncoderException {
File f = new File("D:\\project\\test\\test.mp4");
FFMPEGLocator locator = new FFMPEGLocator() {
@Override
protected String getFFMPEGExecutablePath() {
// TODO Auto-generated method stub
return "D:\\project\\test\\ffmpeg-x86.exe";
}
};
Encoder encoder = new Encoder(locator);
MultimediaInfo info = encoder.getInfo(f);
long duration = info.getDuration();
System.out.println("影片长: "+formatTime(duration));
}
/**
*
* @param ms 输入毫秒数
* @return 输入 3天5小时25分钟22秒382毫秒 这样的格式
*/
public static String formatTime(long ms) {
int ss = 1000;
int mi = ss * 60;
int hh = mi * 60;
int dd = hh * 24;
long day = ms / dd;
long hour = (ms - day * dd) / hh;
long minute = (ms - day * dd - hour * hh) / mi;
long second = (ms - day * dd - hour * hh - minute * mi) / ss;
long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;
StringBuffer sb = new StringBuffer();
if (day > 0) {
sb.append(day + "天");
}
if (hour > 0) {
sb.append(hour + "小时");
}
if (minute > 0) {
sb.append(minute + "分");
}
if (second > 0) {
sb.append(second + "秒");
}
if (milliSecond > 0) {
sb.append(milliSecond + "毫秒");
}
return sb.toString();
}
}
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|