FileTest.java 2.6 KB

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