Parcourir la source

更新对视频文件的处理

reghao il y a 2 ans
Parent
commit
b1f1864d85

+ 1 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/controller/ObjectUploadController.java

@@ -113,8 +113,7 @@ public class ObjectUploadController {
 
         UploadFileRet uploadFileRet = fileProcessor.process(objectResult, channelId);
         if (uploadFileRet == null) {
-            String url = objectNameService.getObjectUrl(objectResult.getObjectName());
-            uploadFileRet = new UploadFileRet(objectResult.getObjectId(), url);
+            return WebResult.failWithMsg("processing file failed");
         }
         return WebResult.success(uploadFileRet);
     }

+ 3 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/service/PutObjectService.java

@@ -6,6 +6,7 @@ import cn.reghao.dfs.store.model.po.FileMeta;
 import cn.reghao.dfs.store.model.vo.ObjectProp;
 import cn.reghao.dfs.store.model.vo.ObjectResult;
 import cn.reghao.dfs.store.util.FileType;
+import cn.reghao.dfs.store.util.StringUtil;
 import cn.reghao.jutil.jdk.security.DigestUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
@@ -93,10 +94,11 @@ public class PutObjectService {
         return new ObjectResult(objectName, objectId, fileType, savedPath, dupObjectId);
     }
 
-    public ObjectResult copyObject(String fromObjectName, String suffix) {
+    public ObjectResult copyObject(String fromObjectName) {
         FileMeta fileMeta = objectRepository.getByObjectName(fromObjectName);
         int fileType = fileMeta.getFileType();
 
+        String suffix = StringUtil.getSuffix(fromObjectName);
         String filename = fileMeta.getFilename();
         String savedPath = "";
         boolean diskFile = fileMeta.getDiskFile();

+ 2 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/task/AudioFileProcessor.java

@@ -49,7 +49,7 @@ public class AudioFileProcessor {
         String originalObjectId = objectResult.getObjectId();
         boolean duplicate = objectResult.isDuplicate();
         if (duplicate) {
-            ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName, ".m4a");
+            ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName);
             String objectId1 = objectResult1.getObjectId();
             String url1 = objectNameService.getObjectUrl(objectResult1.getObjectName());
 
@@ -77,7 +77,7 @@ public class AudioFileProcessor {
             return uploadFileRet;
         }
 
-        ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName, ".m4a");
+        ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName);
         String objectId1 = objectResult1.getObjectId();
         String url1 = objectNameService.getObjectUrl(objectResult1.getObjectName());
         AudioFile audioFile = new AudioFile(originalObjectId, objectId1, audioCodec, url1);

+ 3 - 4
dfs-store/src/main/java/cn/reghao/dfs/store/task/ImageFileProcessor.java

@@ -218,8 +218,7 @@ public class ImageFileProcessor {
 
     private ObjectResult getCopiedObject(String url) {
         String objectName = objectNameService.getObjectNameFromUrl(url);
-        String format = StringUtil.getSuffix(objectName);
-        return putObjectService.copyObject(objectName, format);
+        return putObjectService.copyObject(objectName);
     }
 
     private ObjectResult getJpegObject(ObjectResult objectResult, String format) throws Exception {
@@ -228,7 +227,7 @@ public class ImageFileProcessor {
         ObjectResult objectResult1;
         if (imageFormats.contains(format)) {
             String jpegObjectName = objectResult.getObjectName();
-            objectResult1 = putObjectService.copyObject(jpegObjectName, "."+format);
+            objectResult1 = putObjectService.copyObject(jpegObjectName);
         } else {
             byte[] bytes = ImageOps.convert2jpg(new File(absolutePath));
             objectResult1 = saveImage(originalObjectName, bytes, ".jpeg");
@@ -243,7 +242,7 @@ public class ImageFileProcessor {
         ObjectResult objectResult1;
         if (format.equals("webp")) {
             String webpObjectName = objectResult.getObjectName();
-            objectResult1 = putObjectService.copyObject(webpObjectName, ".webp");
+            objectResult1 = putObjectService.copyObject(webpObjectName);
         } else {
             BufferedImage bi = ImageIO.read(new File(absolutePath));
             ByteArrayOutputStream baos = new ByteArrayOutputStream();

+ 15 - 22
dfs-store/src/main/java/cn/reghao/dfs/store/task/VideoFileProcessor.java

@@ -52,31 +52,28 @@ public class VideoFileProcessor {
 
     public UploadFileRet process(ObjectResult objectResult) {
         String objectName = objectResult.getObjectName();
-        String objectId = objectResult.getObjectId();
+        String videoFileId = objectResult.getObjectId();
         boolean duplicate = objectResult.isDuplicate();
         if (duplicate) {
             String dupObjectId = objectResult.getDupObjectId();
-            VideoFile videoFile = mediaRepository.findVideoFile(dupObjectId);
-            boolean horizontal = videoFile.getHorizontal();
-            int duration = videoFile.getDuration();
-            VideoFile videoFile1 = new VideoFile(objectId, horizontal, duration);
-
             VideoUrl videoUrl = mediaRepository.findVideoUrl(dupObjectId);
             String urlType = videoUrl.getUrlType();
             String quality = videoUrl.getQuality();
             int width = videoUrl.getWidth();
             int height = videoUrl.getHeight();
-
-            String url = objectNameService.getObjectUrl(objectName);
-            String objectName1 = objectNameService.getObjectNameFromUrl(url);
-            ObjectResult objectResult1 = putObjectService.copyObject(objectName1, ".mp4");
+            String objectName1 = objectNameService.getObjectNameFromUrl(videoUrl.getUrl());
+            ObjectResult objectResult1 = putObjectService.copyObject(objectName1);
             String objectId1 = objectResult1.getObjectId();
             String url1 = objectNameService.getObjectUrl(objectName1);
+            VideoUrl videoUrl1 = new VideoUrl(videoFileId, objectId1, urlType, url1, quality, width, height);
 
-            VideoUrl videoUrl1 = new VideoUrl(objectId, objectId1, urlType, url1, quality, width, height);
-            mediaRepository.saveVideoFile(videoFile1, videoUrl1);
+            VideoFile videoFile = mediaRepository.findVideoFile(dupObjectId);
+            boolean horizontal = videoFile.getHorizontal();
+            int duration = videoFile.getDuration();
+            VideoFile videoFile1 = new VideoFile(videoFileId, horizontal, duration);
 
-            return new UploadFileRet(objectId1, url1);
+            mediaRepository.saveVideoFile(videoFile1, videoUrl1);
+            return new UploadFileRet(videoFileId, url1);
         }
 
         String absolutePath = objectResult.getAbsolutePath();
@@ -96,7 +93,7 @@ public class VideoFileProcessor {
         if (videoCodecs.contains(videoCodec)) {
             AudioProps audioProps = mediaProps.getAudioProps();
             if (audioProps != null && !audioCodecs.contains(audioProps.getCodecName())) {
-                log.error("{} 对象的音频非 aac 编码, 暂不处理", objectName);
+                log.error("{} 对象的音频非 aac&mp3 编码, 暂不处理", objectName);
                 return null;
             }
         } else {
@@ -104,26 +101,22 @@ public class VideoFileProcessor {
             return null;
         }
 
-        String videoFileId = objectId;
         int width = videoProps.getCodedWidth().intValue();
         int height = videoProps.getCodedHeight().intValue();
         boolean horizontal = width>height;
         int duration = videoProps.getDuration().intValue();
         VideoFile videoFile = new VideoFile(videoFileId, horizontal, duration);
 
-        MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-        String urlType = FileType.getVideoUrlType(absolutePath);
-
         String originalObjectName = objectResult.getObjectName();
-        ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName, ".mp4");
+        ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName);
         String objectName1 = objectResult1.getObjectName();
         String objectId1 = objectResult1.getObjectId();
         String url1 = objectNameService.getObjectUrl(objectName1);
-
+        MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
+        String urlType = FileType.getVideoUrlType(absolutePath);
         VideoUrl videoUrl  = new VideoUrl(videoFileId, objectId1, urlType, url1, mediaResolution);;
         mediaRepository.saveVideoFile(videoFile, videoUrl);
-
-        return new UploadFileRet(objectId1, url1);
+        return new UploadFileRet(videoFileId, url1);
         //log.info("添加视频格式转码任务");
         //threadPool.submit(new ConvertTask());
     }