From 502b21147d89149cd905d234c2a860a3b937d8d1 Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Tue, 24 Oct 2023 09:42:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=96=B9=E5=BC=8F=20=E5=9C=A8=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E5=8C=85=E9=87=8C=E9=9D=A2=20=E4=B8=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=9B=E5=BB=BA=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=80=8C=E5=AF=BC=E8=87=B4=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/MediaFilePreviewImpl.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java index 022cc43c..caf7b5d3 100644 --- a/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java @@ -38,6 +38,7 @@ public class MediaFilePreviewImpl implements FilePreview { String cacheName = fileAttribute.getcacheName(); String outFilePath = fileAttribute.getoutFilePath(); boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); + String type = fileAttribute.getSuffix(); String[] mediaTypesConvert = FileType.MEDIA_TYPES_CONVERT; //获取支持的转换格式 boolean mediaTypes = false; for(String temp : mediaTypesConvert){ @@ -58,13 +59,12 @@ public class MediaFilePreviewImpl implements FilePreview { if(mediaTypes){ convertedUrl=convertToMp4(filePath,outFilePath); }else { - convertedUrl =outFilePath; //不是http协议的 但是不是转换格式的直接输出 + convertedUrl =outFilePath; //其他协议的 不需要转换方式的文件 支持输出 } } catch (Exception e) { e.printStackTrace(); } if (convertedUrl == null ) { - fileHandlerService.addConvertedFile(cacheName, "error"); //失败加入缓存 return otherFilePreview.notSupportedFile(model, fileAttribute, "视频转换异常,请联系管理员"); } if (ConfigConstants.isCacheEnabled()) { @@ -77,8 +77,11 @@ public class MediaFilePreviewImpl implements FilePreview { } return MEDIA_FILE_PREVIEW_PAGE; } - model.addAttribute("mediaUrl", url); - return MEDIA_FILE_PREVIEW_PAGE; + if(type.equals(FileType.MEDIA)){ // 支持输出 只限默认格式 + model.addAttribute("mediaUrl", url); + return MEDIA_FILE_PREVIEW_PAGE; + } + return otherFilePreview.notSupportedFile(model, fileAttribute, "系统还不支持该格式文件的在线预览"); } /** * 检查视频文件转换是否已开启,以及当前文件是否需要转换 @@ -101,6 +104,13 @@ public class MediaFilePreviewImpl implements FilePreview { if(desFile.exists()){ return outFilePath; } + int index = outFilePath.lastIndexOf("."); + String folder = outFilePath.substring(0, index); + File path = new File(folder); + //目录不存在 创建新的目录 + if (!path.exists()) { + path.mkdirs(); + } frameGrabber.start(); recorder = new FFmpegFrameRecorder(outFilePath, frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), frameGrabber.getAudioChannels()); // recorder.setImageHeight(640);