Prechádzať zdrojové kódy

视频上传走本地ffmpeg

xw 1 deň pred
rodič
commit
48683f98f5

+ 16 - 2
fs-service/src/main/java/com/fs/utils/VideoUtil.java

@@ -13,6 +13,20 @@ import java.util.regex.Pattern;
 
 @Slf4j
 public class VideoUtil {
+
+    /** 与项目 AudioUtils 等模块一致:优先 C:\ffmpeg.exe,其次 PATH 中的 ffmpeg */
+    private static String resolveFfmpegCommand() {
+        String winPath = "C:\\ffmpeg.exe";
+        if (new File(winPath).exists()) {
+            return winPath;
+        }
+        String envPath = System.getenv("FFMPEG_PATH");
+        if (envPath != null && !envPath.isEmpty() && new File(envPath).exists()) {
+            return envPath;
+        }
+        return "ffmpeg";
+    }
+
     /**
      * 获取视频元信息(宽高、大小、时长等)
      */
@@ -20,7 +34,7 @@ public class VideoUtil {
         Map<String, Object> videoInfo = new HashMap<>();
         String videoPath = videoFile.getAbsolutePath();
         String[] command = {
-                "ffmpeg",
+                resolveFfmpegCommand(),
                 "-i", videoPath
         };
 
@@ -76,7 +90,7 @@ public class VideoUtil {
      */
     public static void extractFirstFrame(String videoPath, String outputImagePath) throws IOException, InterruptedException {
         String[] command = {
-                "ffmpeg",
+                resolveFfmpegCommand(),
                 "-ss", "00:00:01.000",  // 精准定位到第1秒
                 "-i", videoPath,        // 输入视频路径
                 "-vframes", "1",        // 只提取1帧