|
@@ -10,29 +10,28 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
+import java.io.*;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+
|
|
|
@Component
|
|
|
public class FFMPEG {
|
|
|
@Resource
|
|
|
private Environment environment;
|
|
|
private static String config;
|
|
|
- private static String ffmepgPath = "/mnt/newdatadrive/apps/ffmpeg/ffmpeg-master/bin/ffmpeg";
|
|
|
- private static String logoPath="/mnt/newdatadrive/data/runtime/jar-instance/manager-api/logo/logo.png";
|
|
|
+ private static String ffmepgPath = "/mnt/newdatadrive/apps/ffmpeg/ffmpeg-master/ffmpeg-resource/ffmpeg";
|
|
|
+ private static String logoPath = "/mnt/newdatadrive/data/runtime/jar-instance/manager-api/logo/logo.png";
|
|
|
|
|
|
@PostConstruct
|
|
|
public void setValue() {
|
|
|
config = environment.getProperty("cm.config");
|
|
|
if ("dev".equals(config)) {
|
|
|
- ffmepgPath="E:\\kaick\\tools\\idmZIP\\ffmpeg-6.1-essentials_build\\bin\\ffmpeg.exe";
|
|
|
+ ffmepgPath = "E:\\kaick\\tools\\idmZIP\\ffmpeg-6.1-essentials_build\\bin\\ffmpeg.exe";
|
|
|
logoPath = "D\\\\:logo.png";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 日志对象
|
|
|
*/
|
|
@@ -120,7 +119,7 @@ public class FFMPEG {
|
|
|
}
|
|
|
int markHeight= 50;
|
|
|
int markWidth = 50;
|
|
|
- if (!StringUtils.isEmpty(dto.get("width")) ) {
|
|
|
+ if (!org.springframework.util.StringUtils.isEmpty(dto.get("width"))) {
|
|
|
markHeight = (int) (Integer.parseInt(dto.get("width")) * 0.1);
|
|
|
markWidth = markHeight;
|
|
|
}
|
|
@@ -185,7 +184,6 @@ public class FFMPEG {
|
|
|
String secondsString = new FFMPEG().videoTransfer(dto);
|
|
|
logger.info("转换共用:" + secondsString + "秒");
|
|
|
if (StringUtils.isBlank(secondsString)) {
|
|
|
- logger.error("视频添加水印异常!");
|
|
|
throw new RuntimeException("视频添加水印异常!");
|
|
|
}
|
|
|
return OSSUtils.fileUpload(new File(filePath));
|
|
@@ -208,7 +206,9 @@ public class FFMPEG {
|
|
|
String width = "";
|
|
|
try {
|
|
|
ProcessBuilder builder = new ProcessBuilder();
|
|
|
- builder.command(cmd);
|
|
|
+ String join = StringUtils.join(cmd, " ");
|
|
|
+ logger.info("join:"+join);
|
|
|
+ builder.command(new String[]{"sh", "-c", join});
|
|
|
final Process p = builder.start();
|
|
|
//从输入流中读取视频信息
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
|
@@ -218,8 +218,9 @@ public class FFMPEG {
|
|
|
sb.append(line);
|
|
|
}
|
|
|
br.close();
|
|
|
- System.out.println(sb.toString());
|
|
|
-
|
|
|
+ int resultCode = p.waitFor();
|
|
|
+ logger.info("resultCode:"+resultCode);
|
|
|
+ logger.info(sb.toString());
|
|
|
int start = sb.indexOf("Video:");
|
|
|
String substring = sb.substring(start);
|
|
|
String[] split = substring.split("\\),");
|
|
@@ -238,7 +239,10 @@ public class FFMPEG {
|
|
|
width = xes[1].trim().split(" ")[0];
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
+ logger.error("出错了:[\u001B[31m {} \u001B[0m]", stringWriter);
|
|
|
+ logger.error("获取视频文件分辨率异常!");
|
|
|
}
|
|
|
map.put("height", height);
|
|
|
map.put("width", width);
|