Skip to content

Commit

Permalink
test: 获取视频封面日志
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed Apr 30, 2024
1 parent 1ebe8a9 commit 9dca76f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ private static void setMusic(File file, Update update) {
}

private void setMediaCover(String fileId, String username, String fileName, String relativePath, Update update) {
log.info("setMediaCover:{}", fileName);
String coverPath = videoProcessService.getVideoCover(fileId, username, relativePath, fileName);
log.info("coverPath:{}", coverPath);
if (!CharSequenceUtil.isBlank(coverPath)) {
if (update == null) {
update = new Update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,25 @@ public String getVideoCover(String fileId, String username, String relativePath,
double videoDuration = getVideoInfo(videoPath).getDuration();
ProcessBuilder processBuilder = getVideoCoverProcessBuilder(videoPath, outputPath, videoDuration);
Process process = processBuilder.start();
int exitCode = process.waitFor();
if (exitCode == 0) {

boolean finished = process.waitFor(10, TimeUnit.SECONDS);
if (finished && process.exitValue() == 0) {
if (FileUtil.exist(outputPath)) {
return outputPath;
} else {
log.error("处理完成后输出文件不存在。");
}
} else {
printErrorInfo(processBuilder);
if (!finished) {
// 超时后处理
process.destroy(); // 尝试正常终止
process.destroyForcibly(); // 强制终止
log.error("进程超时并被终止。");
printErrorInfo(processBuilder);
} else {
// 进程结束但退出码非0
printErrorInfo(processBuilder, process);
}
}
return null;
} catch (InterruptedException e) {
Expand Down Expand Up @@ -416,6 +428,18 @@ private void startConvert(String username, String relativePath, String fileName,
commonFileService.pushMessage(username, fileDocument, "updateFile");
}

private static void printErrorInfo(ProcessBuilder processBuilder, Process process) throws IOException {
printErrorInfo(processBuilder);
// 打印process的错误输出
try (InputStream inputStream = process.getErrorStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = reader.readLine()) != null) {
log.error(line);
}
}
}

private static void printErrorInfo(ProcessBuilder processBuilder) {
// 打印命令 用空格连接
String command = String.join(" ", processBuilder.command());
Expand Down

0 comments on commit 9dca76f

Please sign in to comment.