|
@@ -68,18 +68,8 @@ 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*");
|
|
|
|
- // 获取本地 hostname
|
|
|
|
-// 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);
|
|
|
|
try {
|
|
try {
|
|
String rootDirectoryPathOfMinio = minioConfiguration.getProjectResultDirectory() + projectId + "/" + taskId + "/";
|
|
String rootDirectoryPathOfMinio = minioConfiguration.getProjectResultDirectory() + projectId + "/" + taskId + "/";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
@@ -102,14 +92,15 @@ public class VideoService {
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
// 获取屏幕号创建新的虚拟屏幕
|
|
// 获取屏幕号创建新的虚拟屏幕
|
|
- final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
|
|
- log.info("获取新的屏幕号:" + 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);
|
|
|
|
- OsUtil.exec(xvfbCommand2);
|
|
|
|
- OsUtil.exec(esminiCommand2);
|
|
|
|
|
|
+// final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
|
|
+// log.info("获取新的屏幕号:" + newScreenNum);
|
|
|
|
+// final String xvfbCommand = constantConfiguration.getXvfbCommand().replaceAll("screen-num", String.valueOf(newScreenNum));
|
|
|
|
+// final String esminiCommand = constantConfiguration.getEsminiCommand().replaceAll("screen-num", String.valueOf(newScreenNum)) + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
|
|
|
|
+ final String esminiCommand = constantConfiguration.getEsminiCommand() + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
|
|
|
|
+// OsUtil.exec(xvfbCommand);
|
|
|
|
+ OsUtil.exec(esminiCommand);
|
|
log.info("删除 esmini 进程。");
|
|
log.info("删除 esmini 进程。");
|
|
- OsUtil.kill(esminiCommand2);
|
|
|
|
|
|
+ OsUtil.kill(esminiCommand);
|
|
StringBuilder removeCommand = new StringBuilder();
|
|
StringBuilder removeCommand = new StringBuilder();
|
|
removeCommand.append("rm -f ");
|
|
removeCommand.append("rm -f ");
|
|
int num = 14;
|
|
int num = 14;
|
|
@@ -123,18 +114,17 @@ public class VideoService {
|
|
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;
|
|
|
|
- log.info("删除全部图片==" + removeAll);
|
|
|
|
- OsUtil.exec(removeAll);
|
|
|
|
|
|
+// String removeAll = "rm -rf " + pictureDirectoryPath;
|
|
|
|
+// log.info("删除全部图片==" + removeAll);
|
|
|
|
+// OsUtil.exec(removeAll);
|
|
//6 将视频上传到 minio
|
|
//6 将视频上传到 minio
|
|
MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, minioConfiguration.getBucketName(), videoTargetPathOfMinio);
|
|
MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, minioConfiguration.getBucketName(), videoTargetPathOfMinio);
|
|
log.info("上传成功:" + videoTargetPathOfMinio);
|
|
log.info("上传成功:" + videoTargetPathOfMinio);
|
|
- OsUtil.kill(xvfbCommand2);
|
|
|
|
|
|
+// OsUtil.kill(xvfbCommand);
|
|
//* -------------------------------- 删除临时文件 --------------------------------
|
|
//* -------------------------------- 删除临时文件 --------------------------------
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new RuntimeException("视频生成失败。", e);
|
|
throw new RuntimeException("视频生成失败。", e);
|
|
} finally {
|
|
} finally {
|
|
-// customRedisClient.increment(cpuNodeParallelismKey, 1);
|
|
|
|
customRedisClient.unlock(lockName);
|
|
customRedisClient.unlock(lockName);
|
|
customRedisClient.set(generateVideoKey, "1");
|
|
customRedisClient.set(generateVideoKey, "1");
|
|
}
|
|
}
|