Просмотр исходного кода

修改视频分辨率判断错误的 bug

reghao 3 лет назад
Родитель
Сommit
32135df146

+ 2 - 2
src/main/java/cn/reghao/dfs/store/service/media/MediaQuality.java

@@ -27,9 +27,9 @@ public class MediaQuality {
                 }
             }
         } else {
-            currentAbs = Math.abs(width-arr[0].getWidth());
+            currentAbs = Math.abs(width-arr[0].getHeight());
             for (int i = 1; i < arr.length; i++) {
-                int currentAbs1 = Math.abs(width-arr[i].getWidth());
+                int currentAbs1 = Math.abs(width-arr[i].getHeight());
                 if (currentAbs1 < currentAbs) {
                     currentAbs = currentAbs1;
                     resolution = arr[i];

+ 21 - 0
src/test/java/FileTest.java

@@ -1,10 +1,14 @@
+import cn.reghao.dfs.store.service.media.MediaQuality;
+import cn.reghao.dfs.store.service.media.MediaResolution;
 import cn.reghao.dfs.store.util.media.ImageOps;
+import cn.reghao.dfs.store.util.media.VideoOps;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 
 import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
 import java.io.*;
+import java.util.Map;
 
 /**
  * @author reghao
@@ -39,4 +43,21 @@ public class FileTest {
             }
         }
     }
+
+    @Test
+    public void videoQualityTest() throws IOException {
+        String filePath = "/run/media/reghao/98ecd3fd-ec20-4566-acfc-fba9b9c7c9c2/1ren.tv/32987234/rtmp_20220827_190000.mp4";
+        Map<String, Object> map = VideoOps.videoProps(new File(filePath));
+        int width = (Integer) map.get("width");
+        int height = (Integer) map.get("height");
+        boolean horizontal = width >= height;
+        int duration = ((Long) map.get("duration")).intValue();
+        double fps = (Double) map.get("fps");
+        int frameLength = (Integer) map.get("frameLength");
+        int length = (Integer) map.get("length");
+        String rotate = (String) map.get("rotate");
+
+        MediaResolution reqQuality = MediaQuality.getQuality(width, height);
+        System.out.println();
+    }
 }