lyhzzz 3 лет назад
Родитель
Сommit
f4a00d9857
1 измененных файлов с 5 добавлено и 17 удалено
  1. 5 17
      src/main/java/com/fdkankan/fusion/common/util/VideoUtil.java

+ 5 - 17
src/main/java/com/fdkankan/fusion/common/util/VideoUtil.java

@@ -1,5 +1,6 @@
 package com.fdkankan.fusion.common.util;
 
+import com.fdkankan.common.util.CreateObjUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.bytedeco.ffmpeg.avcodec.AVPacket;
@@ -84,12 +85,13 @@ public class VideoUtil {
                 String format = "%s -y -i %s -vcodec copy -bsf:v h264_mp4toannexb -f mpegts %s";
                 String name = UUID.randomUUID().toString().replace("-","");
                 String command = String.format(format, "ffmpeg", fromVideoFile, newVideoFile +"/"+name + ".ts");
-                execCommand(command);
+                CreateObjUtil.callshell(command);
                 voidTS.add(newVideoFile +"/"+name + ".ts");
             }
             StringBuilder tsPath = new StringBuilder();
             tsPath.append("ffmpeg");
             tsPath.append(" -i ");
+            tsPath.append("'");
             tsPath.append("concat:");
             for (int t = 0; t < voidTS.size(); t++) {
                 if (t != voidTS.size() - 1) {
@@ -98,6 +100,7 @@ public class VideoUtil {
                     tsPath.append(voidTS.get(t));
                 }
             }
+            tsPath.append("'");
             tsPath.append(" -vcodec ");
             tsPath.append(" copy ");
             tsPath.append(" -bsf:a ");
@@ -105,7 +108,7 @@ public class VideoUtil {
             tsPath.append(" -movflags ");
             tsPath.append(" +faststart ");
             tsPath.append(newVideoFile +"/"+fileName);
-            execCommand(tsPath.toString());
+            CreateObjUtil.callshell(tsPath.toString());
             //删除生成的ts文件
             for (String filePath : voidTS) {
                 File file = new File(filePath);
@@ -119,20 +122,5 @@ public class VideoUtil {
         }
     }
 
-    private static void execCommand(String command) throws IOException {
-        log.info("执行command: {}",command);
-        Process pr = Runtime.getRuntime().exec(command);
-        pr.getOutputStream().close();
-        pr.getInputStream().close();
-        pr.getErrorStream().close();
-        try {
-            pr.waitFor();
-            Thread.sleep(1000);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        } finally {
-            pr.destroy();
-        }
-    }
 
 }