import cn.reghao.dfs.store.util.FileType; import cn.reghao.jutil.media.FFmpegWrapper; import cn.reghao.jutil.media.MediaQuality; import cn.reghao.jutil.media.MediaResolution; import cn.reghao.jutil.media.model.AudioProps; import cn.reghao.jutil.media.model.MediaProps; import cn.reghao.jutil.media.model.VideoProps; import cn.reghao.jutil.jdk.security.DigestUtil; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author reghao * @date 2023-03-22 16:19:12 */ @Slf4j public class FileTest { public void walkDir(Path path) throws IOException { Files.walkFileTree(path, new FileVisitor<>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String absolutePath = file.toString(); //process(absolutePath); unique(absolutePath); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } private void process(String absolutePath) { MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath); if (mediaProps == null) { log.error("{} 没有媒体信息", absolutePath); return; } AudioProps audioProps = mediaProps.getAudioProps(); if (audioProps == null) { log.error("{} 没有音频信息", absolutePath); return; } VideoProps videoProps = mediaProps.getVideoProps(); if (videoProps == null) { log.error("{} 没有视频信息", absolutePath); return; } String audioCodec = audioProps.getCodecName(); String videoCodec = videoProps.getCodecName(); int width = videoProps.getCodedWidth().intValue(); int height = videoProps.getCodedHeight().intValue(); if ("aac".equals(audioCodec) && "h264".equals(videoCodec)) { MediaResolution mediaResolution = MediaQuality.getQuality(width, height); } else { log.error("{} 不是 aac&h264", absolutePath); } } Map map = new HashMap<>(); List list = new ArrayList<>(); private void unique(String absolutePath) { try { String sha256sum = DigestUtil.sha256sum(absolutePath); String filePath = map.get(sha256sum); if (filePath == null) { map.put(sha256sum, filePath); } else { log.info("{} 已存在", filePath); list.add(filePath); } } catch (Exception e) { e.printStackTrace(); } } @Test public void test22() throws IOException { //String baseDir = "/home/reghao/mnt/porn/1.待发布/13996.反差婊系列/p/"; //Path path = Path.of(baseDir); //walkDir(path); String filePath = "/home/reghao/Downloads/仁和区 2.m4a"; filePath = "/home/reghao/Downloads/三生三世.wav"; String mediaType = FileType.getMediaType(filePath); MediaProps mediaProps = FFmpegWrapper.getMediaProps(filePath); //FFmpegWrapper.convertAudio(filePath, "/home/reghao/Downloads/三生三世.m4a"); System.out.println(); } }