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

    1.下载jar

    http://www.sauronsoftware.it/projects/jave/download.php

    2.将下载的jar加入到项目中

     3.代码

       @RequestMapping(value = "uploadBatchFile",method = RequestMethod.POST)
        @ResponseBody
        public Object uploadBatchFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) throws IOException, InterruptedException {
            HttpSession session = request.getSession();
            // "/upload"是你自己定义的上传目录
            // linux 下的路径
    //        String temp = session.getServletContext().getRealPath("/upload");
            // window 下的路径
            String temp = session.getServletContext().getRealPath("\upload");
            File tempDir = new File(temp);
            if (!tempDir.exists()){
                tempDir.mkdir();
            }
            File copyFilePath = new File(tempDir,file.getOriginalFilename());
            file.transferTo(copyFilePath);
            //文件存储路径
            // linux -- /data/wwwroot/video.xiaoxiao.cool/upload/f20cd0d0a6154f2dce2c7059a8a62167.mp4
            // window -- E:\IdeaProjects\video_film\target\demo\upload\f20cd0d0a6154f2dce2c7059a8a62167.mp4
            // linux
    //        String tempFilePath = temp + "/" + file.getOriginalFilename();
            // window
            String tempFilePath = temp + "\" + file.getOriginalFilename();
            long size = getSize(tempFilePath);
            System.err.println("时长 : " + size);
            //获取完时长,如果使用的是oss存储,则需要将服务器上的文件删除,减少存储空间
            copyFilePath.delete();
            Map map = Maps.newHashMap();
            map.put("tempDir",temp);
            map.put("tempFilePath",tempFilePath);
            map.put("size",size);
            return JsonData.success(map) ;
        }
    

      

      
      //获取时长的方法 单位秒
      //url - 视频的绝对路径
      long
    getSize(String url){ File source = new File(url); Encoder encoder = new Encoder(); long sum =0; try { MultimediaInfo m = encoder.getInfo(source); sum = m.getDuration()/1000; } catch (Exception e) { e.printStackTrace(); } System.out.println(sum); return sum; }
  • 相关阅读:
    【Little Demo】左右按钮tab选项卡双切换
    【Little Demo】从简单的Tab标签到Tab图片切换
    前端工程师说明(仅以自勉)
    CSS 布局整理
    【Javascript Demo】图片瀑布流实现
    【jQuery Demo】图片瀑布流实现
    【CSS Demo】纯 CSS 打造 Flow-Steps 导航
    【CSS Demo】网站页面变灰
    gradlew命令
    Fragment中不能使用自定义带参构造函数
  • 原文地址:https://www.cnblogs.com/SeaWxx/p/12985638.html
Copyright © 2011-2022 走看看