| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import cn.reghao.jutil.media.FFmpegWrapper;
- import cn.reghao.jutil.media.MediaQuality;
- import cn.reghao.jutil.media.MediaResolution;
- import cn.reghao.jutil.media.po.AudioProps;
- import cn.reghao.jutil.media.po.MediaProps;
- import cn.reghao.jutil.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 = 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<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);
- String filePath = "/run/media/reghao/a4d27bae-50d7-4d3b-9e55-7641f52277e5/1ren.tv/2/1125457010/rtmp_1664557007.flv";
- MediaProps mediaProps = FFmpegWrapper.getMediaProps(filePath);
- System.out.println();
- }
- }
|