|
@@ -33,7 +33,6 @@ import java.math.RoundingMode;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
-import java.util.Set;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -69,18 +68,18 @@ public class VideoService {
|
|
* 生成视频
|
|
* 生成视频
|
|
*/
|
|
*/
|
|
public void generateVideo(String generateVideoKey, String nodeName, String projectId, String projectType, String maxSimulationTime, String taskId) {
|
|
public void generateVideo(String generateVideoKey, String nodeName, String projectId, String projectType, String maxSimulationTime, String taskId) {
|
|
- final Set<String> cpuNodeParallelismKeys = customRedisClient.keys("cpu-node*");
|
|
|
|
|
|
+// final Set<String> cpuNodeParallelismKeys = customRedisClient.keys("cpu-node*");
|
|
// 获取本地 hostname
|
|
// 获取本地 hostname
|
|
- final String hostName = OsUtil.getHostName();
|
|
|
|
- String cpuNodeParallelismKey = "cpu-node:" + nodeName + ":parallelism";
|
|
|
|
- for (String tempCpuNodeParallelismKey : cpuNodeParallelismKeys) {
|
|
|
|
- if (tempCpuNodeParallelismKey.contains(hostName)) {
|
|
|
|
- cpuNodeParallelismKey = tempCpuNodeParallelismKey;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// final String hostName = OsUtil.getHostName();
|
|
|
|
+// String cpuNodeParallelismKey = "cpu-node:" + nodeName + ":parallelism";
|
|
|
|
+// for (String tempCpuNodeParallelismKey : cpuNodeParallelismKeys) {
|
|
|
|
+// if (tempCpuNodeParallelismKey.contains(hostName)) {
|
|
|
|
+// cpuNodeParallelismKey = tempCpuNodeParallelismKey;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
String lockName = "video-lock-" + taskId;
|
|
String lockName = "video-lock-" + taskId;
|
|
customRedisClient.lock(lockName, 1000L, (Long.parseLong(maxSimulationTime) + 10) * 1000L);
|
|
customRedisClient.lock(lockName, 1000L, (Long.parseLong(maxSimulationTime) + 10) * 1000L);
|
|
- customRedisClient.decrement(cpuNodeParallelismKey, 1);
|
|
|
|
|
|
+// customRedisClient.decrement(cpuNodeParallelismKey, 1);
|
|
try {
|
|
try {
|
|
String rootDirectoryPathOfMinio = minioConfiguration.getProjectResultDirectory() + projectId + "/" + taskId + "/";
|
|
String rootDirectoryPathOfMinio = minioConfiguration.getProjectResultDirectory() + projectId + "/" + taskId + "/";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
@@ -98,8 +97,7 @@ public class VideoService {
|
|
MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), csv1PathOfMinio, csv1PathOfLinux);
|
|
MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), csv1PathOfMinio, csv1PathOfLinux);
|
|
MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), csv2PathOfMinio, csv2PathOfLinux);
|
|
MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), csv2PathOfMinio, csv2PathOfLinux);
|
|
log.info("生成 xosc 文件。");
|
|
log.info("生成 xosc 文件。");
|
|
- String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId,
|
|
|
|
- projectType);
|
|
|
|
|
|
+ String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId, projectType);
|
|
log.info("启动虚拟窗口并通过 esmini 截图。");
|
|
log.info("启动虚拟窗口并通过 esmini 截图。");
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
@@ -107,9 +105,7 @@ public class VideoService {
|
|
final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
log.info("获取新的屏幕号:" + newScreenNum);
|
|
log.info("获取新的屏幕号:" + newScreenNum);
|
|
final String xvfbCommand2 = constantConfiguration.getXvfbCommand().replaceAll("screen-num", String.valueOf(newScreenNum));
|
|
final String xvfbCommand2 = constantConfiguration.getXvfbCommand().replaceAll("screen-num", String.valueOf(newScreenNum));
|
|
- final String esminiCommand2 = constantConfiguration.getEsminiCommand().replaceAll("screen-num", String.valueOf(newScreenNum))
|
|
|
|
- + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double
|
|
|
|
- .parseDouble(maxSimulationTime), 2);
|
|
|
|
|
|
+ final String esminiCommand2 = constantConfiguration.getEsminiCommand().replaceAll("screen-num", String.valueOf(newScreenNum)) + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
|
|
OsUtil.exec(xvfbCommand2);
|
|
OsUtil.exec(xvfbCommand2);
|
|
OsUtil.exec(esminiCommand2);
|
|
OsUtil.exec(esminiCommand2);
|
|
log.info("删除 esmini 进程。");
|
|
log.info("删除 esmini 进程。");
|
|
@@ -125,9 +121,7 @@ public class VideoService {
|
|
String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video/" + videoName;
|
|
String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video/" + videoName;
|
|
FileUtil.createParentDirectory(videoTargetPathOfLinux);
|
|
FileUtil.createParentDirectory(videoTargetPathOfLinux);
|
|
String videoTargetPathOfMinio = rootDirectoryPathOfMinio + videoName;
|
|
String videoTargetPathOfMinio = rootDirectoryPathOfMinio + videoName;
|
|
- OsUtil.exec("ffmpeg -f image2 -framerate 30 -start_number " + num + " -i "
|
|
|
|
- + pictureDirectoryPath + "/screenshot_%05d.tga" + " -c:v libx264 -vf format=yuv420p -crf 20 "
|
|
|
|
- + videoTargetPathOfLinux);
|
|
|
|
|
|
+ OsUtil.exec("ffmpeg -f image2 -framerate 30 -start_number " + num + " -i " + pictureDirectoryPath + "/screenshot_%05d.tga" + " -c:v libx264 -vf format=yuv420p -crf 20 " + videoTargetPathOfLinux);
|
|
//删除生成的临时文件
|
|
//删除生成的临时文件
|
|
String removeAll = "rm -rf " + pictureDirectoryPath;
|
|
String removeAll = "rm -rf " + pictureDirectoryPath;
|
|
log.info("删除全部图片==" + removeAll);
|
|
log.info("删除全部图片==" + removeAll);
|
|
@@ -140,7 +134,7 @@ public class VideoService {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new RuntimeException("视频生成失败。", e);
|
|
throw new RuntimeException("视频生成失败。", e);
|
|
} finally {
|
|
} finally {
|
|
- customRedisClient.increment(cpuNodeParallelismKey, 1);
|
|
|
|
|
|
+// customRedisClient.increment(cpuNodeParallelismKey, 1);
|
|
customRedisClient.unlock(lockName);
|
|
customRedisClient.unlock(lockName);
|
|
customRedisClient.set(generateVideoKey, "1");
|
|
customRedisClient.set(generateVideoKey, "1");
|
|
}
|
|
}
|