ehlxr 1 éve
szülő
commit
8898928d99

+ 11 - 6
etl-core/src/main/java/com/tzld/crawler/etl/util/VideoUtils.java

@@ -28,12 +28,13 @@ import com.tzld.crawler.etl.common.enums.ExceptionEnum;
 import com.tzld.crawler.etl.common.exception.CommonException;
 import com.tzld.crawler.etl.model.dto.VideoInfoDto;
 import net.bramp.ffmpeg.FFprobe;
-import net.bramp.ffmpeg.probe.FFmpegFormat;
 import net.bramp.ffmpeg.probe.FFmpegProbeResult;
 import net.bramp.ffmpeg.probe.FFmpegStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.List;
+
 /**
  * @author ehlxr
  * @since 2023-06-26 18:01.
@@ -46,13 +47,17 @@ public class VideoUtils {
             FFprobe ffprobe = new FFprobe(ffprobePath);
             FFmpegProbeResult probeResult = ffprobe.probe(videoPath);
 
-            FFmpegFormat format = probeResult.getFormat();
+            List<FFmpegStream> streams = probeResult.getStreams();
+            int height = 0, width = 0;
+            for (FFmpegStream stream : streams) {
+                height = height <= 0 ? stream.height : height;
+                width = width <= 0 ? stream.width : width;
+            }
 
-            FFmpegStream stream = probeResult.getStreams().get(0);
             return VideoInfoDto.newBuilder()
-                    .duration((long) format.duration)
-                    .height(stream.height)
-                    .width(stream.width)
+                    .duration((long) probeResult.getFormat().duration)
+                    .height(height)
+                    .width(width)
                     .build();
         } catch (Exception e) {
             log.error("get video {} info by ffprobe error.", videoPath, e);