|
@@ -7,6 +7,7 @@ import ws.schild.jave.process.ffmpeg.DefaultFFMPEGLocator;
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
|
+import java.util.logging.Level;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
public class FfmpegUtil {
|
|
public class FfmpegUtil {
|
|
@@ -52,6 +53,35 @@ public class FfmpegUtil {
|
|
System.out.println(getTargetTimeThumbnail(url, targetPath, timestamp));
|
|
System.out.println(getTargetTimeThumbnail(url, targetPath, timestamp));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static boolean getTargetTimeThumbnail1(String url, String targetPath, String timestamp) {
|
|
|
|
+ try {
|
|
|
|
+ // 手动指定 FFmpeg 可执行文件路径
|
|
|
|
+ String ffmpegPath = "/usr/bin/ffmpeg"; // 根据实际情况修改
|
|
|
|
+ ProcessBuilder processBuilder = new ProcessBuilder(ffmpegPath, "-ss", timestamp, "-i", url, "-vframes", "1", targetPath);
|
|
|
|
+ Process process = processBuilder.start();
|
|
|
|
+
|
|
|
|
+ // 获取 FFmpeg 的标准错误输出
|
|
|
|
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
|
|
|
|
+ String line;
|
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
|
+ log.info("FFmpeg error output: " + line);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 等待进程执行完毕
|
|
|
|
+ int exitCode = process.waitFor();
|
|
|
|
+ if (exitCode == 0) {
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException | InterruptedException e) {
|
|
|
|
+ log.error("getTargetTimeThumbnail error", e);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
public static boolean getTargetTimeThumbnail(String url, String targetPath, String timestamp) {
|
|
public static boolean getTargetTimeThumbnail(String url, String targetPath, String timestamp) {
|
|
try {
|
|
try {
|