日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java 获取视频时间_java 获取视频时间

發布時間:2024/1/8 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 获取视频时间_java 获取视频时间 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

//先將視頻保存到項目生成臨時文件,獲取時長后刪除臨時文件

//使用fastdfs進行文件上傳

@RequestMapping("/uploadVideoToFast")

@ResponseBodypublic Map uploadVideoToFast(@RequestParam("file") MultipartFile file)

throws IOException, InterruptedException {

File toFile= null;

InputStream ins= null;

ins=file.getInputStream();

toFile= newFile(file.getOriginalFilename());

inputStreamToFile(ins, toFile);

ins.close();

String length=ReadVideoTime(toFile);

Map url = UploadVideoDemo.testUploadStream(accessKeyId, accessKeySecret, "視頻",

file.getOriginalFilename(), file.getInputStream());

url.put("length", length);returnurl;

}privateString ReadVideoTime(File source) throws InterruptedException {

Encoder encoder= newEncoder();

String length= "";try{

MultimediaInfo m=encoder.getInfo(source);long ls = m.getDuration() / 1000;int hour = (int) (ls / 3600);int minute = (int) (ls % 3600) / 60;int second = (int) (ls - hour * 3600 - minute * 60);

length= hour + ":" + minute + ":" +second;

}catch(Exception e) {

e.printStackTrace();

}

Thread.sleep(1000);

System.out.println(source.getAbsolutePath());

System.out.println(source.getPath());

System.out.println(length);

System.out.println(source.delete());returnlength;

}public static voidinputStreamToFile(InputStream ins, File file) {try{

OutputStream os= newFileOutputStream(file);int bytesRead = 0;byte[] buffer = new byte[8192];while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {

os.write(buffer,0, bytesRead);

}

os.close();

ins.close();

}catch(Exception e) {

e.printStackTrace();

}

}

總結

以上是生活随笔為你收集整理的java 获取视频时间_java 获取视频时间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。