Bladeren bron

VideoUrl 中添加 videoCodec 和 audioCodec 两个字段

reghao 2 jaren geleden
bovenliggende
commit
c6efab07c6

+ 6 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/model/po/VideoUrl.java

@@ -16,6 +16,8 @@ import lombok.NoArgsConstructor;
 public class VideoUrl extends BaseObject<Integer> {
     private String videoFileId;
     private String objectId;
+    private String videoCodec;
+    private String audioCodec;
     private String urlType;
     private String url;
     private Long bitRate;
@@ -24,10 +26,12 @@ public class VideoUrl extends BaseObject<Integer> {
     private Integer height;
     private Integer order;
 
-    public VideoUrl(String videoFileId, String objectId, String urlType, String url,
-                    Long bitRate, MediaResolution mediaResolution) {
+    public VideoUrl(String videoFileId, String objectId, String videoCodec, String audioCodec,
+                    String urlType, String url, Long bitRate, MediaResolution mediaResolution) {
         this.videoFileId = videoFileId;
         this.objectId = objectId;
+        this.videoCodec = videoCodec;
+        this.audioCodec = audioCodec;
         this.urlType = urlType;
         this.url = url;
         this.bitRate = bitRate;

+ 4 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/task/ConvertTask.java

@@ -48,9 +48,12 @@ public class ConvertTask implements Runnable {
             int width = videoProps.getCodedWidth().intValue();
             int height = videoProps.getCodedHeight().intValue();
 
+            String videoCodec = "h264";
+            String audioCodec = "aac";
             long bitRate = videoProps.getBitRate();
             MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-            VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, VideoUrlType.mp4.name(), url, bitRate, mediaResolution);
+            VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, videoCodec, audioCodec,
+                    VideoUrlType.mp4.name(), url, bitRate, mediaResolution);
             //videoUrlMapper.save(videoUrl);
             destFile.delete();
         } catch (Exception e) {

+ 19 - 13
dfs-store/src/main/java/cn/reghao/dfs/store/task/VideoFileProcessor.java

@@ -34,7 +34,7 @@ import java.util.concurrent.ExecutorService;
 @Slf4j
 @Service
 public class VideoFileProcessor {
-    private VideoRepository videoRepository;
+    private final VideoRepository videoRepository;
     private final PutObjectService putObjectService;
     private final ObjectNameService objectNameService;
     private final FileStoreService fileStoreService;
@@ -69,6 +69,8 @@ public class VideoFileProcessor {
                 return null;
             }
 
+            String videoCodec = videoUrl.getVideoCodec();
+            String audioCodec = videoUrl.getAudioCodec();
             String urlType = videoUrl.getUrlType();
             String url = objectNameService.getObjectUrl(objectName);
             long bitRate = videoUrl.getBitRate();
@@ -76,7 +78,8 @@ public class VideoFileProcessor {
             int width = videoUrl.getWidth();
             int height = videoUrl.getHeight();
             int order = 1;
-            VideoUrl videoUrl1 = new VideoUrl(videoFileId, videoFileId, urlType, url, bitRate, quality, width, height, order);
+            VideoUrl videoUrl1 = new VideoUrl(videoFileId, videoFileId, videoCodec, audioCodec,
+                    urlType, url, bitRate, quality, width, height, order);
 
             videoRepository.saveVideoFile(videoFile1, videoUrl1);
             return new UploadFileRet(videoFileId, url, true);
@@ -96,7 +99,13 @@ public class VideoFileProcessor {
         }
 
         String videoCodec = mediaProps.getVideoProps().getCodecName();
-        if (videoCodecs.contains(videoCodec)) {
+        String audioCodec = null;
+        AudioProps audioProps1 = mediaProps.getAudioProps();
+        if (audioProps1 != null) {
+            audioCodec = audioProps1.getCodecName();
+        }
+
+        /*if (videoCodecs.contains(videoCodec)) {
             AudioProps audioProps = mediaProps.getAudioProps();
             if (audioProps != null && !audioCodecs.contains(audioProps.getCodecName())) {
                 log.error("{} 对象的音频非 aac&mp3 编码, 暂不处理", objectName);
@@ -105,8 +114,7 @@ public class VideoFileProcessor {
         } else {
             log.error("{} 对象的视频非 h264 编码, 暂不处理", objectName);
             return null;
-        }
-
+        }*/
         int width = videoProps.getCodedWidth().intValue();
         int height = videoProps.getCodedHeight().intValue();
         boolean horizontal = width>height;
@@ -114,18 +122,14 @@ public class VideoFileProcessor {
         VideoFile videoFile = new VideoFile(videoFileId, horizontal, duration);
 
         String originalUrl = objectNameService.getObjectUrl(objectName);
-
-        /*ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName);
-        String objectName1 = objectResult1.getObjectName();
-        String objectId1 = objectResult1.getObjectId();
-        String url1 = objectNameService.getObjectUrl(objectName1);*/
-
         long bitRate = videoProps.getBitRate();
         MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
         String urlType = FileType.getVideoUrlType(absolutePath);
-        VideoUrl videoUrl  = new VideoUrl(videoFileId, videoFileId, urlType, originalUrl, bitRate, mediaResolution);
+        VideoUrl videoUrl  =
+                new VideoUrl(videoFileId, videoFileId, videoCodec, audioCodec, urlType, originalUrl, bitRate, mediaResolution);
         videoRepository.saveVideoFile(videoFile, videoUrl);
         return new UploadFileRet(videoFileId, originalUrl, true);
+
         //log.info("添加视频格式转码任务");
         //threadPool.submit(new ConvertTask());
     }
@@ -152,11 +156,13 @@ public class VideoFileProcessor {
             ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, originalFilename, sha256sum);
 
             String objectId = objectResult.getObjectId();
+            String videoCodec = "h264";
+            String audioCodec = "aac";
             String url = objectNameService.getObjectUrl(objectResult.getObjectName());
             String urlType = FileType.getVideoUrlType(absolutePath);
             long bitRate = 0;
             MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-            return new VideoUrl(videoFileId, objectId, urlType, url, bitRate, mediaResolution);
+            return new VideoUrl(videoFileId, objectId, videoCodec, audioCodec, urlType, url, bitRate, mediaResolution);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 2 - 2
dfs-store/src/main/resources/mapper/VideoUrlMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.dfs.store.db.mapper.VideoUrlMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into video_url
-        (`video_file_id`,`object_id`,`url_type`,`url`,`bit_rate`,`quality`,`width`,`height`,`order`)
+        (`video_file_id`,`object_id`,`video_codec`,`audio_codec`,`url_type`,`url`,`bit_rate`,`quality`,`width`,`height`,`order`)
         values
-        (#{videoFileId},#{objectId},#{urlType},#{url},#{bitRate},#{quality},#{width},#{height},#{order})
+        (#{videoFileId},#{objectId},#{videoCodec},#{audioCodec},#{urlType},#{url},#{bitRate},#{quality},#{width},#{height},#{order})
     </insert>
 
     <select id="findAll" resultType="cn.reghao.dfs.store.model.po.VideoUrl">