FileTest.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import cn.reghao.dfs.store.service.media.MediaQuality;
  2. import cn.reghao.dfs.store.service.media.MediaResolution;
  3. import cn.reghao.dfs.store.util.media.ImageOps;
  4. import cn.reghao.dfs.store.util.media.VideoOps;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.junit.Test;
  7. import javax.imageio.ImageIO;
  8. import java.awt.image.BufferedImage;
  9. import java.io.*;
  10. import java.util.Map;
  11. /**
  12. * @author reghao
  13. * @date 2022-06-20 14:31:14
  14. */
  15. @Slf4j
  16. public class FileTest {
  17. @Test
  18. public void avatarSizeTest() throws IOException {
  19. String dirPath = "/opt/file/disk0/spider/weibo/img/avatar/";
  20. File dir = new File(dirPath);
  21. for (File file : dir.listFiles()) {
  22. if (file.isDirectory()) {
  23. continue;
  24. }
  25. long len = file.length();
  26. if (len > 1024*1024) {
  27. log.error("{} 大小超过 1MiB, 实际大小为 {}", file.getAbsolutePath(), len/1024);
  28. /*String userId = file.getName().split("\\.")[0];
  29. BufferedImage bufferedImage = ImageIO.read(new FileInputStream(file));
  30. BufferedImage bufferedImage1 = ImageOps.resize(bufferedImage, 2);
  31. String dest = String.format("/opt/file/disk0/spider/bili/img/avatar1/%s.jpg", userId);
  32. File destFile = new File(dest);
  33. ImageIO.write(bufferedImage1, "jpg", destFile);
  34. long len1 = destFile.length();
  35. log.error("{} 大小超过 1MiB, 实际大小为 {}, 调整后的大小为 {}", file.getAbsolutePath(), len/1024, len1/1024);*/
  36. }
  37. }
  38. }
  39. @Test
  40. public void videoQualityTest() throws IOException {
  41. String filePath = "/run/media/reghao/98ecd3fd-ec20-4566-acfc-fba9b9c7c9c2/1ren.tv/32987234/rtmp_20220827_190000.mp4";
  42. Map<String, Object> map = VideoOps.videoProps(new File(filePath));
  43. int width = (Integer) map.get("width");
  44. int height = (Integer) map.get("height");
  45. boolean horizontal = width >= height;
  46. int duration = ((Long) map.get("duration")).intValue();
  47. double fps = (Double) map.get("fps");
  48. int frameLength = (Integer) map.get("frameLength");
  49. int length = (Integer) map.get("length");
  50. String rotate = (String) map.get("rotate");
  51. MediaResolution reqQuality = MediaQuality.getQuality(width, height);
  52. System.out.println();
  53. }
  54. }