标签:
有时间可以写成递归的
1 package org.zln.video.demo1; 2 3 import it.sauronsoftware.jave.Encoder; 4 import it.sauronsoftware.jave.EncoderException; 5 import it.sauronsoftware.jave.InputFormatException; 6 import it.sauronsoftware.jave.MultimediaInfo; 7 8 import java.io.File; 9 10 /** 11 * 统计目录下视频时长 12 * Created by coolkid on 2015/6/13 0013. 13 */ 14 public class CountTime { 15 /*支持的后缀*/ 16 private static final String[] SUFFIX_SUPPORT = {".avi",".mp4"}; 17 18 public static void main(String[] args) throws EncoderException { 19 if (args.length!=1){ 20 throw new RuntimeException("参数错误"); 21 } 22 File file = new File(args[0]); 23 long ls = getLongTime(file); 24 long hour = ls/3600000; 25 long min = (ls - hour*3600000)/60000; 26 long sec = (ls - hour*3600000 - min*60000)/1000; 27 System.out.println("视频时长:"+hour+"时:"+min+"分:"+sec+"秒"); 28 29 } 30 31 public static long getLongTime(File root) throws EncoderException { 32 long t = 0; 33 File[] files = root.listFiles(); 34 for (File file:files){ 35 if (file.getName().endsWith(".mp4")){ 36 Encoder encoder = new Encoder(); 37 MultimediaInfo multimediaInfo = encoder.getInfo(file); 38 t += multimediaInfo.getDuration(); 39 } 40 } 41 return t; 42 } 43 }
这里用到了jave.jar
标签:
原文地址:http://www.cnblogs.com/sherrykid/p/4574037.html