|
@@ -33,7 +33,6 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Set;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -58,8 +57,6 @@ public class VideoService {
|
|
|
//* -------------------------------- Comment --------------------------------
|
|
|
@Value("${scheduler.linux-path.temp}")
|
|
|
private String linuxTempPath;
|
|
|
- @Value("${scheduler.Xvfb-command}")
|
|
|
- private String XvfbCommand;
|
|
|
@Value("${scheduler.esmini-command}")
|
|
|
private String esminiCommand;
|
|
|
@Value("${scheduler.python-command}")
|
|
@@ -75,7 +72,6 @@ public class VideoService {
|
|
|
/**
|
|
|
* 生成视频
|
|
|
*/
|
|
|
- @SneakyThrows
|
|
|
public void generateVideo(String projectId, String projectType, String maxSimulationTime, String taskId) {
|
|
|
final Set<String> cpuNodeParallelismKeys = customRedisClient.keys("cpu-node*");
|
|
|
// 获取本地 hostname
|
|
@@ -87,13 +83,8 @@ public class VideoService {
|
|
|
cpuNodeParallelismKey = tempCpuNodeParallelismKey;
|
|
|
}
|
|
|
}
|
|
|
- // 检查是否有并行度可用
|
|
|
- while (parallelism < 1) {
|
|
|
- parallelism = Integer.parseInt(customRedisClient.get(cpuNodeParallelismKey));
|
|
|
- TimeUnit.SECONDS.sleep(7);
|
|
|
- }
|
|
|
String lockName = "video-lock-" + taskId;
|
|
|
- customRedisClient.lock(lockName, Long.parseLong(maxSimulationTime) + 10L, 1000L);
|
|
|
+ customRedisClient.lock(lockName, 1000L, (Long.parseLong(maxSimulationTime) + 10) * 1000L);
|
|
|
customRedisClient.decrement(cpuNodeParallelismKey, 1);
|
|
|
try {
|
|
|
String rootDirectoryPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/";
|
|
@@ -118,7 +109,6 @@ public class VideoService {
|
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
|
String esminiCommandTemp = esminiCommand + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
|
|
|
- LinuxUtil.execute(XvfbCommand);
|
|
|
LinuxUtil.execute(esminiCommandTemp);
|
|
|
log.info("删除 esmini 进程。");
|
|
|
LinuxUtil.kill(esminiCommandTemp);
|
|
@@ -132,14 +122,9 @@ public class VideoService {
|
|
|
String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video/" + videoName;
|
|
|
FileUtil.createParentDirectory(videoTargetPathOfLinux);
|
|
|
String videoTargetPathOfMinio = rootDirectoryPathOfMinio + videoName;
|
|
|
-
|
|
|
- String execute = LinuxUtil.execute("ffmpeg"
|
|
|
- + " -f image2 -framerate 30 "
|
|
|
- + "-start_number " + num
|
|
|
+ String execute = LinuxUtil.execute("ffmpeg -f image2 -framerate 30 -start_number " + num
|
|
|
+ " -i " + pictureDirectoryPath + "/screenshot_%05d.tga"
|
|
|
- + " -c:v libx264 -vf format=yuv420p -crf 20 "
|
|
|
- + videoTargetPathOfLinux
|
|
|
- );
|
|
|
+ + " -c:v libx264 -vf format=yuv420p -crf 20 " + videoTargetPathOfLinux);
|
|
|
//6 将视频上传到 minio
|
|
|
MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, bucketName, videoTargetPathOfMinio);
|
|
|
log.info("上传成功:" + videoTargetPathOfMinio);
|
|
@@ -152,7 +137,8 @@ public class VideoService {
|
|
|
// FileUtil.rm(osgbPathOfLinux);
|
|
|
// FileUtil.rm(csv1PathOfLinux);
|
|
|
// FileUtil.rm(csv2PathOfLinux);
|
|
|
-
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("视频生成失败。");
|
|
|
} finally {
|
|
|
customRedisClient.decrement(cpuNodeParallelismKey, 1);
|
|
|
customRedisClient.unlock(lockName);
|