|
@@ -3,6 +3,7 @@ package com.css.simulation.resource.video.service;
|
|
|
import api.common.pojo.po.scene.VehicleTypePO;
|
|
|
import api.common.util.FileUtil;
|
|
|
import api.common.util.LinuxUtil;
|
|
|
+import api.common.util.OsUtil;
|
|
|
import api.common.util.StringUtil;
|
|
|
import com.css.simulation.resource.video.configuration.redis.CustomRedisClient;
|
|
|
import com.css.simulation.resource.video.entity.VehicleEntity;
|
|
@@ -10,7 +11,6 @@ import com.css.simulation.resource.video.mapper.ConfigMapper;
|
|
|
import com.css.simulation.resource.video.mapper.SimulationAutomaticProjectMapper;
|
|
|
import com.css.simulation.resource.video.mapper.VehicleMapper;
|
|
|
import com.css.simulation.resource.video.util.MinioUtil;
|
|
|
-import com.css.simulation.resource.video.util.OsUtil;
|
|
|
import io.minio.MinioClient;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -105,39 +105,53 @@ public class VideoService {
|
|
|
MinioUtil.downloadToFile(minioClient, bucketName, csv2PathOfMinio, csv2PathOfLinux);
|
|
|
|
|
|
log.info("生成 xosc 文件。");
|
|
|
- String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId, projectType);
|
|
|
+ String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId,
|
|
|
+ projectType);
|
|
|
log.info("启动虚拟窗口并通过 esmini 截图。");
|
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
|
- String esminiCommandTemp = esminiCommand + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
|
|
|
// 获取屏幕号创建新的虚拟屏幕
|
|
|
final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
|
log.info("获取新的屏幕号:" + newScreenNum);
|
|
|
- final String xvfbCommand2 = xvfbCommand.replaceAll("screenNum", newScreenNum + "");
|
|
|
- LinuxUtil.execute(xvfbCommand2);
|
|
|
- LinuxUtil.execute(esminiCommandTemp);
|
|
|
+ final String xvfbCommand2 = xvfbCommand.replaceAll("screen-num", newScreenNum + "");
|
|
|
+ final String esminiCommand2 = esminiCommand.replaceAll("screen-num", newScreenNum + "")
|
|
|
+ + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double
|
|
|
+ .parseDouble(maxSimulationTime), 2);
|
|
|
+ OsUtil.exec( xvfbCommand2);
|
|
|
+ OsUtil.exec( esminiCommand2);
|
|
|
+
|
|
|
+// LinuxUtil.execute(xvfbCommand2);
|
|
|
+// LinuxUtil.execute(esminiCommand2);
|
|
|
log.info("删除 esmini 进程。");
|
|
|
- LinuxUtil.kill(esminiCommandTemp);
|
|
|
+ OsUtil.kill( esminiCommand2);
|
|
|
+// LinuxUtil.kill(esminiCommand2);
|
|
|
+ StringBuilder removeCommand = new StringBuilder();
|
|
|
+ removeCommand.append("rm -f ");
|
|
|
int num = 14;
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
- String remove = "rm -f " + pictureDirectoryPath + "/screenshot_0000" + i + ".tga";
|
|
|
- LinuxUtil.execute(remove);
|
|
|
+ removeCommand.append(pictureDirectoryPath).append("/screenshot_0000").append(i).append(".tga ");
|
|
|
}
|
|
|
+ OsUtil.kill( removeCommand.toString());
|
|
|
log.info("生成视频。");
|
|
|
String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video/" + videoName;
|
|
|
FileUtil.createParentDirectory(videoTargetPathOfLinux);
|
|
|
String videoTargetPathOfMinio = rootDirectoryPathOfMinio + videoName;
|
|
|
- LinuxUtil.execute("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);
|
|
|
+// LinuxUtil.execute("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);
|
|
|
- LinuxUtil.execute(removeAll);
|
|
|
+ OsUtil.exec( removeAll);
|
|
|
+// LinuxUtil.execute(removeAll);
|
|
|
//6 将视频上传到 minio
|
|
|
MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, bucketName, videoTargetPathOfMinio);
|
|
|
log.info("上传成功:" + videoTargetPathOfMinio);
|
|
|
- LinuxUtil.kill(xvfbCommand2);
|
|
|
+ OsUtil.kill(xvfbCommand2);
|
|
|
+// LinuxUtil.kill(xvfbCommand2);
|
|
|
//* -------------------------------- 删除临时文件 --------------------------------
|
|
|
// FileUtil.rm(xodrPathOfLinux);
|
|
|
// FileUtil.rm(osgbPathOfLinux);
|