1 package test; 2 import it.sauronsoftware.jave.Encoder; 3 import it.sauronsoftware.jave.MultimediaInfo; 4 5 import java.io.File; 6 7 public class ReadVideo { 8 9 public static void main(String[] args){ 10 File source = new File("E:\\马士兵Spring\\"); 11 Encoder encoder = new Encoder(); 12 File[] file = source.listFiles(); 13 long sum =0; 14 for (File file2 : file) { 15 try { 16 MultimediaInfo m = encoder.getInfo(file2); 17 long ls = m.getDuration()/1000; //ls是获取到的秒数 18 sum += ls; 19 } catch (Exception e) { 20 e.printStackTrace(); 21 } 22 } 23 double sum1 = (double)sum; 24 double sum2 =sum1/3600; // 转换成为了小时 25 System.out.println(sum2); 26 } 27 }
以上代码是获取一个目录目录的所有视频的总时长
获取单个视频的时长改改就行了
ps:第一篇博文 需要引入jar包 下载地址