色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

瀏覽:49日期: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
相關文章:
主站蜘蛛池模板: 欧美一级毛片在线 | 欧美成人艳星在线播放 | 日本欧美精品 | 久久久久99精品成人片三人毛片 | 99热免费 | 成人免费夜片在线观看 | 8888奇米四色在线 | 人人公开免费超级碰碰碰视频 | 日本成人不卡视频 | 欧洲一级大片 | 免费看欧美一级a毛片 | 波多野结衣在线看片 | 久久天天躁综合夜夜黑人鲁色 | 中国一级特黄真人毛片 | 欧美成人一区二区 | www.久草| 午夜香蕉成视频人网站高清版 | 91精选视频| 萌白酱粉嫩jk福利在线观看 | 2020国产微拍精品一区二区 | 91亚洲精品在看在线观看高清 | 97人摸人人澡人人人超一碰 | 日韩国产午夜一区二区三区 | 男女扒开双腿猛进入免费网站 | 色综合日韩 | 成人免费在线视频网 | 日本欧美一级aaaaa毛片 | 一区二区三区不卡在线观看 | 精品国产自在在线在线观看 | 美女黄页网站免费进入 | 午夜剧场福利社 | 一级欧美在线的视频 | 中文字幕在线一区二区在线 | 综合久久久久久中文字幕 | 怡红院视频在线观看 | 好湿好紧好痛a级是免费视频 | 91久热| 久久影院在线 | 在线精品播放 | 久久精品亚洲一区二区 | 日韩男人天堂 |