zoukankan      html  css  js  c++  java
  • java读取视频文件时长

    1.下载jar包:http://www.sauronsoftware.it/projects/jave/index.php

    2.上代码  

     1     @RequestMapping(value = "amendFile.htm", produces = "application/json;charset=UTF-8")
     2     @ResponseBody
     3     public String amendFile(MultipartFile file, HttpServletRequest request,
     4             HttpServletResponse response, String equid,String begintime,String endtime) {
     5         log.info(this.getClass().getSimpleName() + "."
     6                 + Thread.currentThread().getStackTrace()[1].getMethodName()
     7                 + "()----start");
     8         
     9         String path =  request.getSession().getServletContext()
    10                 .getRealPath("/")+"resources/"+equid+"/"+begintime.substring(0,begintime.length()-6)+"/";
    11         // 通过文件ID 获取文件存储路径
    12         if (file.isEmpty()) {
    13             return "empty";
    14         }
    15         Map<String, Object> map = new HashMap<String, Object>();
    16         try {
    17             /* 写入文件 */
    18             File targetFile = new File(path, file.getOriginalFilename());
    19             if (!targetFile.exists()) {
    20                 targetFile.mkdirs();
    21             }
    22             file.transferTo(targetFile); // 转储 
    23             Encoder encoder = new Encoder(); 
    24             // zp add 读取视频时长 2017-07-31
    25             try {
    26                  MultimediaInfo m = encoder.getInfo(targetFile);
    27                  long ls = m.getDuration(); 
    28                  ls = Math.round((double)ls/1000); 
    29                  map.put("timeLength", Math.round(ls));
    30             } catch (Exception e) {
    31                 e.printStackTrace();
    32             } 
    33             // 读取视频时长结束  2017-07-31
    34             response.addHeader("Access-Control-Allow-Origin", "*");
    35             if(targetFile.exists()){
    36                 
    37                 map.put("success", "success");
    38                 ObjectMapper mapper = new ObjectMapper();
    39                 String content = mapper.writeValueAsString(map);
    40                 return content;
    41             }else{
    42                 map.put("error", "error");
    43                 ObjectMapper mapper = new ObjectMapper();
    44                 String content = mapper.writeValueAsString(map);
    45                 return content;
    46             }
    47             
    48         } catch (Exception e) {
    49             e.printStackTrace();
    50         }
    51         log.info(this.getClass().getSimpleName() + "."
    52                 + Thread.currentThread().getStackTrace()[1].getMethodName()
    53                 + "()----end");
    54         return "success";
    55     } 
    View Code

    其中最重要的代码就是:

     1  // zp add 读取视频时长 2017-07-31
     2             try {
     3                  MultimediaInfo m = encoder.getInfo(targetFile);
     4                  long ls = m.getDuration(); 
     5                  ls = Math.round((double)ls/1000); 
     6                  map.put("timeLength", Math.round(ls));
     7             } catch (Exception e) {
     8                 e.printStackTrace();
     9             } 
    10             // 读取视频时长结束  2017-07-31
    View Code
  • 相关阅读:
    题目一:使用Java实现二维数组中的查找
    算法的时间复杂度
    爬虫----爬虫存储库
    爬虫----爬虫解析库Beautifulsoup模块
    问卷调查
    爬虫----爬虫请求库selenium
    爬虫----爬虫请求库requests
    爬虫----爬虫基本原理
    python金融与量化分析------Matplotlib(绘图和可视化)
    Python与金融量化分析----金融与量化投资
  • 原文地址:https://www.cnblogs.com/pengpengzhang/p/7262652.html
Copyright © 2011-2022 走看看