java 获取视频时间_java 获取视频时间
//先將視頻保存到項(xiàng)目生成臨時(shí)文件,獲取時(shí)長(zhǎng)后刪除臨時(shí)文件
//使用fastdfs進(jìn)行文件上傳
@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();
}
}
總結(jié)
以上是生活随笔為你收集整理的java 获取视频时间_java 获取视频时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 战舰帝国服务器维护,【图片】9月17日更
- 下一篇: 好用在线html编辑器,求一款好用的ht