|
@@ -2,12 +2,13 @@ package com.css.simulation.resource.video.service;
|
|
|
|
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
import api.common.pojo.po.scene.VehicleTypePO;
|
|
import api.common.pojo.po.scene.VehicleTypePO;
|
|
-import api.common.pojo.vo.model.VehicleVO;
|
|
|
|
import api.common.util.FileUtil;
|
|
import api.common.util.FileUtil;
|
|
import api.common.util.LinuxUtil;
|
|
import api.common.util.LinuxUtil;
|
|
|
|
+import api.common.util.StringUtil;
|
|
import com.css.simulation.resource.video.mapper.ConfigMapper;
|
|
import com.css.simulation.resource.video.mapper.ConfigMapper;
|
|
import com.css.simulation.resource.video.mapper.SimulationAutomaticProjectMapper;
|
|
import com.css.simulation.resource.video.mapper.SimulationAutomaticProjectMapper;
|
|
import com.css.simulation.resource.video.mapper.VehicleMapper;
|
|
import com.css.simulation.resource.video.mapper.VehicleMapper;
|
|
|
|
+import com.css.simulation.resource.video.pojo.po.VehiclePO;
|
|
import com.css.simulation.resource.video.util.MinioUtil;
|
|
import com.css.simulation.resource.video.util.MinioUtil;
|
|
import io.minio.MinioClient;
|
|
import io.minio.MinioClient;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
@@ -26,6 +27,7 @@ import java.io.File;
|
|
import java.io.OutputStreamWriter;
|
|
import java.io.OutputStreamWriter;
|
|
import java.io.Writer;
|
|
import java.io.Writer;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+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;
|
|
@@ -50,10 +52,13 @@ public class VideoService {
|
|
public static final String oldXoscRelativePath = "xosc/simulation_my0.xosc";
|
|
public static final String oldXoscRelativePath = "xosc/simulation_my0.xosc";
|
|
public static final String csv1Name = "Ego.csv";
|
|
public static final String csv1Name = "Ego.csv";
|
|
public static final String csv2Name = "evaluation.csv";
|
|
public static final String csv2Name = "evaluation.csv";
|
|
|
|
+ public static final String videoName = "simulation_output.mp4";
|
|
|
|
|
|
//* -------------------------------- Comment --------------------------------
|
|
//* -------------------------------- Comment --------------------------------
|
|
@Value("${scheduler.linux-path.temp}")
|
|
@Value("${scheduler.linux-path.temp}")
|
|
String linuxTempPath;
|
|
String linuxTempPath;
|
|
|
|
+ @Value("${scheduler.Xvfb-command}")
|
|
|
|
+ String XvfbCommand;
|
|
@Value("${scheduler.esmini-command}")
|
|
@Value("${scheduler.esmini-command}")
|
|
String esminiCommand;
|
|
String esminiCommand;
|
|
@Value("${scheduler.python-command}")
|
|
@Value("${scheduler.python-command}")
|
|
@@ -68,7 +73,7 @@ public class VideoService {
|
|
* 生成视频
|
|
* 生成视频
|
|
*/
|
|
*/
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
- public ResponseBodyVO<String> generateVideo(String projectId, String projectType, String taskId) {
|
|
|
|
|
|
+ public ResponseBodyVO<String> generateVideo(String projectId, String projectType, String maxSimulationTime, String taskId) {
|
|
//1 获取两个 csv 的目录,和 xodr 和 osgb 三个路径
|
|
//1 获取两个 csv 的目录,和 xodr 和 osgb 三个路径
|
|
String rootDirectoryPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/";
|
|
String rootDirectoryPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
@@ -88,26 +93,27 @@ public class VideoService {
|
|
|
|
|
|
//3 生成 xosc 文件
|
|
//3 生成 xosc 文件
|
|
String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId, projectType);
|
|
String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId, projectType);
|
|
|
|
+ // 启动虚拟窗口
|
|
//4 生成图片
|
|
//4 生成图片
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
FileUtil.createDirectory(pictureDirectoryPath);
|
|
- String esminiCommandTemp = esminiCommand + " "
|
|
|
|
- + xoscPath + " " + pictureDirectoryPath + "/screenshot";
|
|
|
|
- String esminiResult = LinuxUtil.execute(esminiCommandTemp);
|
|
|
|
|
|
+ String esminiCommandTemp = esminiCommand + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
|
|
|
|
+ LinuxUtil.execute2(XvfbCommand, esminiCommandTemp);
|
|
|
|
+// String esminiResult = LinuxUtil.execute(esminiCommandTemp);
|
|
//5 生成视频
|
|
//5 生成视频
|
|
- String videoName = "simulation_output.mp4";
|
|
|
|
- String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video";
|
|
|
|
- FileUtil.createDirectory(videoTargetPathOfLinux);
|
|
|
|
- String videoTargetPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/" + videoName;
|
|
|
|
|
|
+ String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video/" + videoName;
|
|
|
|
+ FileUtil.createParentDirectory(videoTargetPathOfLinux);
|
|
|
|
+ String videoTargetPathOfMinio = rootDirectoryPathOfMinio + videoName;
|
|
|
|
|
|
String execute = LinuxUtil.execute("ffmpeg"
|
|
String execute = LinuxUtil.execute("ffmpeg"
|
|
+ " -f image2 -framerate 30 "
|
|
+ " -f image2 -framerate 30 "
|
|
+ " -i " + pictureDirectoryPath + "/screenshot_%05d.tga"
|
|
+ " -i " + pictureDirectoryPath + "/screenshot_%05d.tga"
|
|
+ " -c:v libx264 -vf format=yuv420p -crf 20 "
|
|
+ " -c:v libx264 -vf format=yuv420p -crf 20 "
|
|
- + videoTargetPathOfLinux + "/" + videoName
|
|
|
|
|
|
+ + videoTargetPathOfLinux
|
|
);
|
|
);
|
|
//6 将视频上传到 minio
|
|
//6 将视频上传到 minio
|
|
- MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux + videoName, bucketName, videoTargetPathOfMinio);
|
|
|
|
|
|
+ MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, bucketName, videoTargetPathOfMinio);
|
|
|
|
+ log.info("上传成功:" + videoTargetPathOfMinio);
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -280,11 +286,11 @@ public class VideoService {
|
|
String vehicleId = configMapper.getVehicleId(vehicle);
|
|
String vehicleId = configMapper.getVehicleId(vehicle);
|
|
|
|
|
|
log.info("VideoService--vehicleById 车辆 Id 为:" + vehicleId);
|
|
log.info("VideoService--vehicleById 车辆 Id 为:" + vehicleId);
|
|
- VehicleVO vehicleInfo = vehicleMapper.getVehicleInfo(vehicleId);
|
|
|
|
|
|
+ VehiclePO vehicleInfo = vehicleMapper.getVehicleInfo(vehicleId);
|
|
log.info("VideoService--vehicleById 车辆信息为:" + vehicleInfo);
|
|
log.info("VideoService--vehicleById 车辆信息为:" + vehicleInfo);
|
|
|
|
|
|
//自车模型
|
|
//自车模型
|
|
- String car = vehicleInfo.getVehicleTypeStr().substring(0, vehicleInfo.getVehicleTypeStr().indexOf(","));
|
|
|
|
|
|
+ String car = vehicleInfo.getVehicleType().substring(0, vehicleInfo.getVehicleType().indexOf(","));
|
|
car = car.substring(0, 1).toLowerCase() + car.substring(1);
|
|
car = car.substring(0, 1).toLowerCase() + car.substring(1);
|
|
if (car.contains("truck")) {
|
|
if (car.contains("truck")) {
|
|
po.setVehicleCategory("truck");
|
|
po.setVehicleCategory("truck");
|
|
@@ -300,12 +306,8 @@ public class VideoService {
|
|
po.setVehicleCategory("motorbike");
|
|
po.setVehicleCategory("motorbike");
|
|
} else if (car.contains("bicycle")) {
|
|
} else if (car.contains("bicycle")) {
|
|
po.setVehicleCategory("bicycle");
|
|
po.setVehicleCategory("bicycle");
|
|
- } else if (car.contains("bicycle")) {
|
|
|
|
- po.setVehicleCategory("bicycle");
|
|
|
|
} else if (car.contains("train")) {
|
|
} else if (car.contains("train")) {
|
|
po.setVehicleCategory("train");
|
|
po.setVehicleCategory("train");
|
|
- } else if (car.contains("tram")) {
|
|
|
|
- po.setVehicleCategory("tram");
|
|
|
|
} else {
|
|
} else {
|
|
po.setVehicleCategory("car");
|
|
po.setVehicleCategory("car");
|
|
}
|
|
}
|
|
@@ -315,16 +317,17 @@ public class VideoService {
|
|
//车后距
|
|
//车后距
|
|
BigDecimal mo2 = new BigDecimal("2");
|
|
BigDecimal mo2 = new BigDecimal("2");
|
|
BigDecimal rearDistance = vehicleInfo.getRearDistance();
|
|
BigDecimal rearDistance = vehicleInfo.getRearDistance();
|
|
|
|
+ BigDecimal CenterX;
|
|
|
|
+ BigDecimal divide = (frontDistance.add(rearDistance)).divide(mo2, 6, RoundingMode.CEILING);
|
|
if (frontDistance.compareTo(rearDistance) > 0) {
|
|
if (frontDistance.compareTo(rearDistance) > 0) {
|
|
- BigDecimal CenterX = (frontDistance.add(rearDistance)).divide(mo2).subtract(rearDistance);
|
|
|
|
- po.setCenterX(CenterX);
|
|
|
|
|
|
+ CenterX = divide.subtract(rearDistance);
|
|
} else {
|
|
} else {
|
|
- BigDecimal CenterX = (frontDistance.add(rearDistance)).divide(mo2).subtract(frontDistance);
|
|
|
|
- po.setCenterX(CenterX);
|
|
|
|
|
|
+ CenterX = divide.subtract(frontDistance);
|
|
}
|
|
}
|
|
|
|
+ po.setCenterX(CenterX);
|
|
//车高
|
|
//车高
|
|
BigDecimal mo3 = new BigDecimal("3");
|
|
BigDecimal mo3 = new BigDecimal("3");
|
|
- po.setCenterZ(vehicleInfo.getHeightDistance().divide(mo3));
|
|
|
|
|
|
+ po.setCenterZ(vehicleInfo.getHeightDistance().divide(mo3, 6, RoundingMode.CEILING));
|
|
//车左距 车右距
|
|
//车左距 车右距
|
|
BigDecimal LeftDistance = vehicleInfo.getLeftDistance();
|
|
BigDecimal LeftDistance = vehicleInfo.getLeftDistance();
|
|
BigDecimal RightDistance = vehicleInfo.getRightDistance();
|
|
BigDecimal RightDistance = vehicleInfo.getRightDistance();
|
|
@@ -336,11 +339,11 @@ public class VideoService {
|
|
po.setPerformanceMaxDeceleration(vehicleInfo.getMaxDeceleration());
|
|
po.setPerformanceMaxDeceleration(vehicleInfo.getMaxDeceleration());
|
|
BigDecimal moπ = new BigDecimal("3.141516");
|
|
BigDecimal moπ = new BigDecimal("3.141516");
|
|
BigDecimal mo180 = new BigDecimal("180");
|
|
BigDecimal mo180 = new BigDecimal("180");
|
|
- po.setFrontAxleMaxSteering(vehicleInfo.getMaxSteeringAngle().multiply(moπ).divide(mo180));
|
|
|
|
|
|
+ po.setFrontAxleMaxSteering(vehicleInfo.getMaxSteeringAngle().multiply(moπ).divide(mo180, 6, RoundingMode.CEILING));
|
|
po.setFrontAxleWheelDiameter(vehicleInfo.getWheelDiameter());
|
|
po.setFrontAxleWheelDiameter(vehicleInfo.getWheelDiameter());
|
|
BigDecimal mo4 = new BigDecimal("4");
|
|
BigDecimal mo4 = new BigDecimal("4");
|
|
BigDecimal mo5 = new BigDecimal("5");
|
|
BigDecimal mo5 = new BigDecimal("5");
|
|
- po.setFrontAxleTrackWidth(LeftDistance.add(RightDistance).multiply(mo4).divide(mo5));
|
|
|
|
|
|
+ po.setFrontAxleTrackWidth(LeftDistance.add(RightDistance).multiply(mo4).divide(mo5, 6, RoundingMode.CEILING));
|
|
po.setFrontAxlePositionX(po.getCenterX());
|
|
po.setFrontAxlePositionX(po.getCenterX());
|
|
po.setFrontAxlePositionZ(po.getCenterZ());
|
|
po.setFrontAxlePositionZ(po.getCenterZ());
|
|
|
|
|