需要安装一下 ffmpeg
配置一下 环境变量
Runtime runtime = Runtime.getRuntime();
Process exec = runtime.exec("ffprobe -i " + filePath + " -show_entries format=duration -v quiet -of csv=\"p=0\""); //url/本地文件 都可
InputStreamReader reader = new InputStreamReader(exec.getInputStream());
char[] cbuf = new char[20];
int read = reader.read(cbuf);
if (read> 0 ){
String durationStr = String.valueOf(cbuf).trim();
System.out.println(durationStr);
Double duration = Double.valueOf(durationStr);
Integer second = duration.intValue(); // 秒
Integer minute = duration.longValue()/60; // 分钟
Integer millisecond = duration*1000; // 毫秒
}
获取的是个小数字符串并且自带换行符