浏览代码

生成视频

root 2 年之前
父节点
当前提交
0f4254e2c4

+ 11 - 11
api-common/src/main/java/api/common/util/LinuxUtil.java

@@ -26,17 +26,17 @@ public class LinuxUtil {
         return out.toString();
     }
 
-    public static String execute1(String cmd) throws IOException {
+    public static void execute2(String cmd1, String cmd2) throws IOException, InterruptedException {
         Runtime run = Runtime.getRuntime();
-        Process process = run.exec(cmd);
-        InputStream in = new BufferedInputStream(process.getInputStream());
-        StringBuilder out = new StringBuilder();
-        byte[] b = new byte[8192];
-        for (int n; (n = in.read(b)) != -1; ) {
-            out.append(new String(b, 0, n));
-        }
-        in.close();
-        process.destroy();
-        return out.toString();
+        log.info("开始执行 linux 命令:" + cmd1);
+        Process process1 = run.exec(cmd1);
+        process1.waitFor();
+        log.info("开始执行 linux 命令:" + cmd2);
+        Process process2 = run.exec(cmd2);
+        process2.waitFor();
+        process1.destroy();
+        process2.destroy();
+        log.info("linux 命令执行完成。");
     }
+
 }

+ 6 - 1
simulation-resource-video/src/main/java/com/css/simulation/resource/video/service/VideoService.java

@@ -57,6 +57,8 @@ public class VideoService {
     //* -------------------------------- Comment --------------------------------
     @Value("${scheduler.linux-path.temp}")
     String linuxTempPath;
+    @Value("${scheduler.Xvfb-command}")
+    String XvfbCommand;
     @Value("${scheduler.esmini-command}")
     String esminiCommand;
     @Value("${scheduler.python-command}")
@@ -91,11 +93,13 @@ public class VideoService {
 
         //3 生成 xosc 文件
         String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId, projectType);
+        // 启动虚拟窗口
         //4 生成图片
         String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
         FileUtil.createDirectory(pictureDirectoryPath);
         String esminiCommandTemp = esminiCommand + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
-        String esminiResult = LinuxUtil.execute(esminiCommandTemp);
+        LinuxUtil.execute2(XvfbCommand, esminiCommandTemp);
+//        String esminiResult = LinuxUtil.execute(esminiCommandTemp);
         //5 生成视频
         String videoTargetPathOfLinux = rootDirectoryPathOfLinux + "video/" + videoName;
         FileUtil.createParentDirectory(videoTargetPathOfLinux);
@@ -109,6 +113,7 @@ public class VideoService {
         );
         //6 将视频上传到 minio
         MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, bucketName, videoTargetPathOfMinio);
+        log.info("上传成功:" + videoTargetPathOfMinio);
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }