码迷,mamicode.com
首页 > 其他好文 > 详细

统计指定目录下的视频时长

时间:2015-06-13 21:37:22      阅读:409      评论:0      收藏:0      [点我收藏+]

标签:

有时间可以写成递归的

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!