| mvn install:install-file -Dfile=jave-1.0.2.jar -DgroupId=joinery -DartifactId=jave -Dversion=1.0.2 -Dpackaging=jar |
| |
| <dependency> |
| <groupId>it.sauronsoftware</groupId> |
| <artifactId>jave</artifactId> |
| <version>1.0.2</version> |
| </dependency> |
| import it.sauronsoftware.jave.Encoder; |
| import it.sauronsoftware.jave.MultimediaInfo; |
| import java.io.File; |
| |
| @GetMapping(value = "/getVideoLength") |
| @ApiOperation(value="获取视频时长") |
| public Object getVideoLength(){ |
| File source = new File("C:\\Users\\ychen\\Videos\\test\\video1.flv"); |
| Encoder encoder = new Encoder(); |
| 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(); |
| return "计算出错"; |
| } |
| return new JSONResult(length); |
| } |
| import org.springframework.web.multipart.MultipartFile; |
| import java.io.File; |
| import java.io.FileOutputStream; |
| import java.io.InputStream; |
| import java.io.OutputStream; |
| |
| public class MultipartFileToFile { |
| |
| |
| public static File multipartFileToFile(MultipartFile file) throws Exception { |
| |
| File toFile = null; |
| if (file.equals("") || file.getSize() <= 0) { |
| file = null; |
| } else { |
| InputStream ins = null; |
| ins = file.getInputStream(); |
| toFile = new File(file.getOriginalFilename()); |
| inputStreamToFile(ins, toFile); |
| ins.close(); |
| } |
| return toFile; |
| } |
| |
| |
| private static void inputStreamToFile(InputStream ins, File file) { |
| try { |
| OutputStream os = new FileOutputStream(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(); |
| } |
| } |
| |
| |
| public static void delteTempFile(File file) { |
| if (file != null) { |
| File del = new File(file.toURI()); |
| del.delete(); |
| } |
| } |
| |
| } |
| @GetMapping(value = "/getVideoLength") |
| @ApiOperation(value="获取视频时长") |
| public Object getVideoLength(@RequestParam("file") MultipartFile file) throws IOException { |
| File toFile = null; |
| if (file.equals("") || file.getSize() <= 0) { |
| file = null; |
| } else { |
| InputStream ins = null; |
| ins = file.getInputStream(); |
| toFile = new File(file.getOriginalFilename()); |
| inputStreamToFile(ins, toFile); |
| ins.close(); |
| } |
| |
| Encoder encoder = new Encoder(); |
| String length = ""; |
| try { |
| MultimediaInfo m = encoder.getInfo(toFile); |
| 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(); |
| return "计算出错"; |
| } |
| |
| delteTempFile(toFile); |
| return new JSONResult(length); |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术