|
|
@ -38,6 +38,7 @@ public class MediaFilePreviewImpl implements FilePreview { |
|
|
|
String cacheName = fileAttribute.getcacheName(); |
|
|
|
String cacheName = fileAttribute.getcacheName(); |
|
|
|
String outFilePath = fileAttribute.getoutFilePath(); |
|
|
|
String outFilePath = fileAttribute.getoutFilePath(); |
|
|
|
boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); |
|
|
|
boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); |
|
|
|
|
|
|
|
String type = fileAttribute.getSuffix(); |
|
|
|
String[] mediaTypesConvert = FileType.MEDIA_TYPES_CONVERT; //获取支持的转换格式
|
|
|
|
String[] mediaTypesConvert = FileType.MEDIA_TYPES_CONVERT; //获取支持的转换格式
|
|
|
|
boolean mediaTypes = false; |
|
|
|
boolean mediaTypes = false; |
|
|
|
for(String temp : mediaTypesConvert){ |
|
|
|
for(String temp : mediaTypesConvert){ |
|
|
@ -58,13 +59,12 @@ public class MediaFilePreviewImpl implements FilePreview { |
|
|
|
if(mediaTypes){ |
|
|
|
if(mediaTypes){ |
|
|
|
convertedUrl=convertToMp4(filePath,outFilePath); |
|
|
|
convertedUrl=convertToMp4(filePath,outFilePath); |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
convertedUrl =outFilePath; //不是http协议的 但是不是转换格式的直接输出
|
|
|
|
convertedUrl =outFilePath; //其他协议的 不需要转换方式的文件 支持输出
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (convertedUrl == null ) { |
|
|
|
if (convertedUrl == null ) { |
|
|
|
fileHandlerService.addConvertedFile(cacheName, "error"); //失败加入缓存
|
|
|
|
|
|
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, "视频转换异常,请联系管理员"); |
|
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, "视频转换异常,请联系管理员"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ConfigConstants.isCacheEnabled()) { |
|
|
|
if (ConfigConstants.isCacheEnabled()) { |
|
|
@ -77,9 +77,12 @@ public class MediaFilePreviewImpl implements FilePreview { |
|
|
|
} |
|
|
|
} |
|
|
|
return MEDIA_FILE_PREVIEW_PAGE; |
|
|
|
return MEDIA_FILE_PREVIEW_PAGE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(type.equals(FileType.MEDIA)){ // 支持输出 只限默认格式
|
|
|
|
model.addAttribute("mediaUrl", url); |
|
|
|
model.addAttribute("mediaUrl", url); |
|
|
|
return MEDIA_FILE_PREVIEW_PAGE; |
|
|
|
return MEDIA_FILE_PREVIEW_PAGE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, "系统还不支持该格式文件的在线预览"); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 检查视频文件转换是否已开启,以及当前文件是否需要转换 |
|
|
|
* 检查视频文件转换是否已开启,以及当前文件是否需要转换 |
|
|
|
* @return |
|
|
|
* @return |
|
|
@ -101,6 +104,13 @@ public class MediaFilePreviewImpl implements FilePreview { |
|
|
|
if(desFile.exists()){ |
|
|
|
if(desFile.exists()){ |
|
|
|
return outFilePath; |
|
|
|
return outFilePath; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int index = outFilePath.lastIndexOf("."); |
|
|
|
|
|
|
|
String folder = outFilePath.substring(0, index); |
|
|
|
|
|
|
|
File path = new File(folder); |
|
|
|
|
|
|
|
//目录不存在 创建新的目录
|
|
|
|
|
|
|
|
if (!path.exists()) { |
|
|
|
|
|
|
|
path.mkdirs(); |
|
|
|
|
|
|
|
} |
|
|
|
frameGrabber.start(); |
|
|
|
frameGrabber.start(); |
|
|
|
recorder = new FFmpegFrameRecorder(outFilePath, frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), frameGrabber.getAudioChannels()); |
|
|
|
recorder = new FFmpegFrameRecorder(outFilePath, frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), frameGrabber.getAudioChannels()); |
|
|
|
// recorder.setImageHeight(640);
|
|
|
|
// recorder.setImageHeight(640);
|
|
|
|