av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Java獲取視頻時長、大小的示例

瀏覽:32日期:2022-08-21 14:47:42

項目中有這樣一個需求,網頁上上傳了一個視頻,需要獲取此視頻的時長、大小,把這兩個數據返回給前臺在頁面顯示。后臺使用的是springboot框架,項目部署在linux上面。下面是核心代碼:

1、pom文件中需要導入的jar包依賴

(分為兩部分:核心包、ffmpeg包兩部分,ffmpeg包又分為Windows環境以及Linux環境,同時又區分32位系統以及64位系統。針對于不同的運行環境要導入不同的包,這一點對于開發、測試環境為Window而生產環境為Linux的情況,尤其要注意需要導入所有的包,使其在兩種環境下都能夠使用)

<dependency> <groupId>ws.schild</groupId> <artifactId>jave-all-deps</artifactId> <version>2.6.0</version> </dependency> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-core</artifactId> <version>2.4.5</version> </dependency> <!-- window32位 ffmpeg --> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-win32</artifactId> <version>2.4.5</version> </dependency> <!-- window64位 ffmpeg --> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-win64</artifactId> <version>2.4.5</version> </dependency> <!-- linux32位 ffmpeg --> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-linux32</artifactId> <version>2.4.6</version> </dependency> <!-- linux64位 ffmpeg --> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-linux64</artifactId> <version>2.4.6</version> </dependency>

2、controller層代碼

package com.aaa.bbb.controller;import io.swagger.annotations.Api;import lombok.extern.slf4j.Slf4j;import org.apache.commons.io.FileUtils;import org.springframework.util.ResourceUtils;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import ws.schild.jave.MultimediaInfo;import ws.schild.jave.MultimediaObject;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.math.BigDecimal;import java.math.RoundingMode;import java.nio.channels.FileChannel;@Slf4j@RestController@RequestMapping('/readVideo')@Api(tags = '獲取視頻時長、大小相關信息的接口')public class ReadVideoController {/** * 獲取視頻時長 * * @param fileUrl * @return */@PostMapping('/videoLengthAndSize')public static String getLengthAndSize(@RequestParam String fileUrl) throws FileNotFoundException { ReadVideoController r = new ReadVideoController(); String path = ResourceUtils.getURL('classpath:').getPath() + 'static'; System.out.println('666666666666666666666666666666【' + path + '】666666666666666666666666666666】'); fileUrl = path + fileUrl; String videoLength = r.ReadVideoTime(fileUrl);//視頻時長 System.out.println('===========================視頻時長:' + videoLength + '==========================='); return videoLength;}/** * 視頻時長 * * @param FileUrl * @return */public static String ReadVideoTime(String FileUrl) { File source = new File(FileUrl); String length = ''; try { MultimediaObject instance = new MultimediaObject(source); MultimediaInfo result = instance.getInfo(); long ls = result.getDuration() / 1000; Integer hour = (int) (ls / 3600); Integer minute = (int) (ls % 3600) / 60; Integer second = (int) (ls - hour * 3600 - minute * 60); String hr = hour.toString(); String mi = minute.toString(); String se = second.toString(); if (hr.length() < 2) { hr = '0' + hr; } if (mi.length() < 2) { mi = '0' + mi; } if (se.length() < 2) { se = '0' + se; } length = hr + ':' + mi + ':' + se; } catch (Exception e) { e.printStackTrace(); } return length;} /** * 視頻大小 * * @param source * @return */@SuppressWarnings({'resource'})public static String ReadVideoSize(File source) { FileChannel fc = null; String size = ''; try { FileInputStream fis = new FileInputStream(source); fc = fis.getChannel(); BigDecimal fileSize = new BigDecimal(fc.size()); size = fileSize.divide(new BigDecimal(1024 * 1024), 2, RoundingMode.HALF_UP) + 'MB'; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (null != fc) { try {fc.close(); } catch (IOException e) {e.printStackTrace(); } } } return size;}}

以上就是Java獲取視頻時長、大小的示例的詳細內容,更多關于Java 視頻時長、大小的資料請關注好吧啦網其它相關文章!

標簽: Java
相關文章:
主站蜘蛛池模板: 国产特级毛片aaaaaa | 一本色道久久综合亚洲精品高清 | a视频在线观看 | av三级| 久久成人免费视频 | 在线看av的网址 | 亚洲乱码一区二区 | 亚洲视频在线播放 | 国产精品美女www爽爽爽 | 国产精品亚洲一区二区三区在线 | 亚洲人免费视频 | 久久性av | 亚洲www| 人人人人人爽 | 欧美h版 | 一区二区在线免费观看 | 日韩免费看片 | 亚洲成人av在线播放 | 国产成人99久久亚洲综合精品 | 99久久亚洲 | 97超在线视频 | 精品久久国产 | 在线观看成人精品 | 亚洲视频二| 亚洲精品国产偷自在线观看 | 精品日韩在线 | 高清av在线| 亚洲成av人片在线观看无码 | 视频一区二区三区中文字幕 | 国产日韩精品一区 | 国产成人精品综合 | 亚洲综合无码一区二区 | 玖玖综合在线 | 波多野结衣在线观看一区二区三区 | 亚洲欧美在线免费观看 | 97国产精品视频人人做人人爱 | 国产精品一区二区欧美黑人喷潮水 | 成人在线视频网 | 国产一级黄色网 | 国产91在线视频 | 国产91在线播放精品91 |