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.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.UUID; /** * @author reghao * @date 2022-06-20 14:31:14 */ @Slf4j public class FileTest { @Test public void avatarSizeTest() throws IOException { String dirPath = "/opt/file/disk0/spider/weibo/img/avatar/"; File dir = new File(dirPath); for (File file : dir.listFiles()) { if (file.isDirectory()) { continue; } long len = file.length(); if (len > 1024*1024) { log.error("{} 大小超过 1MiB, 实际大小为 {}", file.getAbsolutePath(), len/1024); /*String userId = file.getName().split("\\.")[0]; BufferedImage bufferedImage = ImageIO.read(new FileInputStream(file)); BufferedImage bufferedImage1 = ImageOps.resize(bufferedImage, 2); String dest = String.format("/opt/file/disk0/spider/bili/img/avatar1/%s.jpg", userId); File destFile = new File(dest); ImageIO.write(bufferedImage1, "jpg", destFile); long len1 = destFile.length(); log.error("{} 大小超过 1MiB, 实际大小为 {}, 调整后的大小为 {}", file.getAbsolutePath(), len/1024, len1/1024);*/ } } } @Test public void videoQualityTest() throws IOException { String filePath = "/run/media/reghao/98ecd3fd-ec20-4566-acfc-fba9b9c7c9c2/1ren.tv/32987234/rtmp_20220827_190000.mp4"; Map 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(); } @Test public void test() throws IOException { String uuid = UUID.randomUUID().toString(); System.out.println(); } }