|
@@ -13,6 +13,20 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class VideoUtil {
|
|
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<>();
|
|
Map<String, Object> videoInfo = new HashMap<>();
|
|
|
String videoPath = videoFile.getAbsolutePath();
|
|
String videoPath = videoFile.getAbsolutePath();
|
|
|
String[] command = {
|
|
String[] command = {
|
|
|
- "ffmpeg",
|
|
|
|
|
|
|
+ resolveFfmpegCommand(),
|
|
|
"-i", videoPath
|
|
"-i", videoPath
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -76,7 +90,7 @@ public class VideoUtil {
|
|
|
*/
|
|
*/
|
|
|
public static void extractFirstFrame(String videoPath, String outputImagePath) throws IOException, InterruptedException {
|
|
public static void extractFirstFrame(String videoPath, String outputImagePath) throws IOException, InterruptedException {
|
|
|
String[] command = {
|
|
String[] command = {
|
|
|
- "ffmpeg",
|
|
|
|
|
|
|
+ resolveFfmpegCommand(),
|
|
|
"-ss", "00:00:01.000", // 精准定位到第1秒
|
|
"-ss", "00:00:01.000", // 精准定位到第1秒
|
|
|
"-i", videoPath, // 输入视频路径
|
|
"-i", videoPath, // 输入视频路径
|
|
|
"-vframes", "1", // 只提取1帧
|
|
"-vframes", "1", // 只提取1帧
|