|
@@ -18,6 +18,7 @@ import cn.reghao.jutil.media.FFmpegWrapper;
|
|
|
import cn.reghao.jutil.media.MediaQuality;
|
|
import cn.reghao.jutil.media.MediaQuality;
|
|
|
import cn.reghao.jutil.media.MediaResolution;
|
|
import cn.reghao.jutil.media.MediaResolution;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
|
|
+import cn.reghao.oss.api.rest.UploadFileRet;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -51,7 +52,8 @@ public class VideoFileProcessor {
|
|
|
this.fileStoreService = fileStoreService;
|
|
this.fileStoreService = fileStoreService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void process(ObjectResult objectResult) {
|
|
|
|
|
|
|
+ public UploadFileRet process(ObjectResult objectResult) {
|
|
|
|
|
+ String objectName = objectResult.getObjectName();
|
|
|
String objectId = objectResult.getObjectId();
|
|
String objectId = objectResult.getObjectId();
|
|
|
boolean duplicate = objectResult.isDuplicate();
|
|
boolean duplicate = objectResult.isDuplicate();
|
|
|
if (duplicate) {
|
|
if (duplicate) {
|
|
@@ -67,29 +69,29 @@ public class VideoFileProcessor {
|
|
|
int width = videoUrl.getWidth();
|
|
int width = videoUrl.getWidth();
|
|
|
int height = videoUrl.getHeight();
|
|
int height = videoUrl.getHeight();
|
|
|
|
|
|
|
|
- String url = objectResult.getUploadFileRet().getUrl();
|
|
|
|
|
|
|
+ String url = objectNameService.getObjectUrl(objectName);
|
|
|
String objectName1 = objectNameService.getObjectNameFromUrl(url);
|
|
String objectName1 = objectNameService.getObjectNameFromUrl(url);
|
|
|
- ObjectResult objectResult1 = putObjectService.copyObject(objectName1);
|
|
|
|
|
|
|
+ ObjectResult objectResult1 = putObjectService.copyObject(objectName1, ".mp4");
|
|
|
String objectId1 = objectResult1.getObjectId();
|
|
String objectId1 = objectResult1.getObjectId();
|
|
|
- String url1 = objectResult1.getUploadFileRet().getUrl();
|
|
|
|
|
|
|
+ String url1 = objectNameService.getObjectUrl(objectName1);
|
|
|
|
|
|
|
|
VideoUrl videoUrl1 = new VideoUrl(objectId, objectId1, urlType, url1, quality, width, height);
|
|
VideoUrl videoUrl1 = new VideoUrl(objectId, objectId1, urlType, url1, quality, width, height);
|
|
|
mediaRepository.saveVideoFile(videoFile1, videoUrl1);
|
|
mediaRepository.saveVideoFile(videoFile1, videoUrl1);
|
|
|
- return;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return new UploadFileRet(objectId1, url1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String objectName = objectResult.getObjectName();
|
|
|
|
|
String absolutePath = objectResult.getAbsolutePath();
|
|
String absolutePath = objectResult.getAbsolutePath();
|
|
|
MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
|
|
MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
|
|
|
if (mediaProps == null) {
|
|
if (mediaProps == null) {
|
|
|
log.info("{} 的 FFmpeg 媒体信息为 null", objectName);
|
|
log.info("{} 的 FFmpeg 媒体信息为 null", objectName);
|
|
|
- return;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
VideoProps videoProps = mediaProps.getVideoProps();
|
|
VideoProps videoProps = mediaProps.getVideoProps();
|
|
|
if (videoProps == null) {
|
|
if (videoProps == null) {
|
|
|
log.info("{} 的 FFmpeg 视频信息为 null", objectName);
|
|
log.info("{} 的 FFmpeg 视频信息为 null", objectName);
|
|
|
- return;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String videoCodec = mediaProps.getVideoProps().getCodecName();
|
|
String videoCodec = mediaProps.getVideoProps().getCodecName();
|
|
@@ -97,11 +99,11 @@ public class VideoFileProcessor {
|
|
|
AudioProps audioProps = mediaProps.getAudioProps();
|
|
AudioProps audioProps = mediaProps.getAudioProps();
|
|
|
if (audioProps != null && !audioCodecs.contains(audioProps.getCodecName())) {
|
|
if (audioProps != null && !audioCodecs.contains(audioProps.getCodecName())) {
|
|
|
log.error("{} 对象的音频非 aac 编码, 暂不处理", objectName);
|
|
log.error("{} 对象的音频非 aac 编码, 暂不处理", objectName);
|
|
|
- return;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
log.error("{} 对象的视频非 h264 编码, 暂不处理", objectName);
|
|
log.error("{} 对象的视频非 h264 编码, 暂不处理", objectName);
|
|
|
- return;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String videoFileId = objectId;
|
|
String videoFileId = objectId;
|
|
@@ -115,18 +117,21 @@ public class VideoFileProcessor {
|
|
|
String urlType = FileType.getVideoUrlType(absolutePath);
|
|
String urlType = FileType.getVideoUrlType(absolutePath);
|
|
|
|
|
|
|
|
String originalObjectName = objectResult.getObjectName();
|
|
String originalObjectName = objectResult.getObjectName();
|
|
|
- ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName);
|
|
|
|
|
|
|
+ ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName, ".mp4");
|
|
|
|
|
+ String objectName1 = objectResult1.getObjectName();
|
|
|
String objectId1 = objectResult1.getObjectId();
|
|
String objectId1 = objectResult1.getObjectId();
|
|
|
- String url = objectResult1.getUploadFileRet().getUrl();
|
|
|
|
|
|
|
+ String url1 = objectNameService.getObjectUrl(objectName1);
|
|
|
|
|
|
|
|
- VideoUrl videoUrl = new VideoUrl(videoFileId, objectId1, urlType, url, mediaResolution);;
|
|
|
|
|
|
|
+ VideoUrl videoUrl = new VideoUrl(videoFileId, objectId1, urlType, url1, mediaResolution);;
|
|
|
mediaRepository.saveVideoFile(videoFile, videoUrl);
|
|
mediaRepository.saveVideoFile(videoFile, videoUrl);
|
|
|
|
|
|
|
|
|
|
+ return new UploadFileRet(objectId1, url1);
|
|
|
//log.info("添加视频格式转码任务");
|
|
//log.info("添加视频格式转码任务");
|
|
|
//threadPool.submit(new ConvertTask());
|
|
//threadPool.submit(new ConvertTask());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private VideoUrl getConvertedVideoUrl(String videoFileId, File file, int width, int height) {
|
|
|
|
|
|
|
+ private VideoUrl getConvertedVideoUrl(String videoFileId, File file, String originalObjectName,
|
|
|
|
|
+ int width, int height, String suffix) {
|
|
|
String contentId = UUID.randomUUID().toString().replace("-", "");
|
|
String contentId = UUID.randomUUID().toString().replace("-", "");
|
|
|
fileStoreService.genFilePath(contentId, file.length());
|
|
fileStoreService.genFilePath(contentId, file.length());
|
|
|
String absolutePath = fileStoreService.genFilePath(contentId, file.length());
|
|
String absolutePath = fileStoreService.genFilePath(contentId, file.length());
|
|
@@ -136,19 +141,19 @@ public class VideoFileProcessor {
|
|
|
throw new IOException(absolutePath + " exist");
|
|
throw new IOException(absolutePath + " exist");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String suffix = "mp4";
|
|
|
|
|
- int ret = FFmpegWrapper.formatCovert(file.getAbsolutePath(), absolutePath + "." + suffix, suffix);
|
|
|
|
|
|
|
+ String format = suffix.replace(".", "");
|
|
|
|
|
+ int ret = FFmpegWrapper.formatCovert(file.getAbsolutePath(), absolutePath + suffix, format);
|
|
|
if (ret != 0) {
|
|
if (ret != 0) {
|
|
|
throw new Exception("视频转码失败");
|
|
throw new Exception("视频转码失败");
|
|
|
}
|
|
}
|
|
|
String sha256sum = DigestUtil.sha256sum(absolutePath);
|
|
String sha256sum = DigestUtil.sha256sum(absolutePath);
|
|
|
|
|
|
|
|
- ObjectProp objectProp = objectNameService.getObjectProp(UploadChannel.video.getCode());
|
|
|
|
|
|
|
+ ObjectProp objectProp = objectNameService.getObjectProp(originalObjectName, suffix);
|
|
|
String originalFilename = "";
|
|
String originalFilename = "";
|
|
|
ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, originalFilename, sha256sum);
|
|
ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, originalFilename, sha256sum);
|
|
|
|
|
|
|
|
- String objectId = objectResult.getUploadFileRet().getUploadId();
|
|
|
|
|
- String url = objectResult.getUploadFileRet().getUrl();
|
|
|
|
|
|
|
+ String objectId = objectResult.getObjectId();
|
|
|
|
|
+ String url = objectNameService.getObjectUrl(objectResult.getObjectName());
|
|
|
String urlType = FileType.getVideoUrlType(absolutePath);
|
|
String urlType = FileType.getVideoUrlType(absolutePath);
|
|
|
MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
|
|
MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
|
|
|
return new VideoUrl(videoFileId, objectId, urlType, url, mediaResolution);
|
|
return new VideoUrl(videoFileId, objectId, urlType, url, mediaResolution);
|