修复 视频转换方式 在压缩包里面 不自动创建文件路径而导致的报错

This commit is contained in:
gaoxiongzaq
2023-10-24 09:42:47 +08:00
parent deb91728d4
commit 502b21147d

View File

@@ -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);