|
|
@@ -0,0 +1,108 @@
|
|
|
+import cn.reghao.dfs.store.util.media.FFmpegWrapper;
|
|
|
+import cn.reghao.dfs.store.util.media.MediaQuality;
|
|
|
+import cn.reghao.dfs.store.util.media.MediaResolution;
|
|
|
+import cn.reghao.dfs.store.util.media.po.AudioProps;
|
|
|
+import cn.reghao.dfs.store.util.media.po.MediaProps;
|
|
|
+import cn.reghao.dfs.store.util.media.po.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 = (int) videoProps.getCodedWidth();
|
|
|
+ int height = (int) videoProps.getCodedHeight();
|
|
|
+ if ("aac".equals(audioCodec) && "h264".equals(videoCodec)) {
|
|
|
+ MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
|
|
|
+ } else {
|
|
|
+ log.error("{} 不是 aac&h264", absolutePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ List<String> 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);
|
|
|
+ }
|
|
|
+}
|