|
@@ -1,5 +1,8 @@
|
|
|
package com.caimei.modules.archive.utils;
|
|
|
|
|
|
+import com.thinkgem.jeesite.common.config.Global;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.util.StringUtils;
|
|
@@ -16,8 +19,12 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
public class FFMPEG {
|
|
|
|
|
|
- @Value("${ffmpeg.path}")
|
|
|
- private static String ffmepgPath;
|
|
|
+ private static String ffmepgPath = Global.getConfig("ffmpeg.path");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日志对象
|
|
|
+ */
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(FFMPEG.class);
|
|
|
|
|
|
public static String dealString(String str) {
|
|
|
Matcher m = Pattern.compile("^frame=.*").matcher(str);
|
|
@@ -92,6 +99,8 @@ public class FFMPEG {
|
|
|
// String ffmpeg_path,String input_path,String video_converted_path,String logo,String screen_size,String xaxis,String yaxis,String vb,String ab
|
|
|
List<String> cmd = new ArrayList<String>();
|
|
|
cmd.add(dto.get("ffmpeg_path"));
|
|
|
+ cmd.add("-protocol_whitelist");
|
|
|
+ cmd.add(dto.get("whitelist"));
|
|
|
cmd.add("-y");
|
|
|
cmd.add("-i");
|
|
|
cmd.add(dto.get("input_path"));
|
|
@@ -138,17 +147,27 @@ public class FFMPEG {
|
|
|
|
|
|
public static Map<String, Object> setVideoWaterMark(String fileUrl, String filePath) {
|
|
|
HashMap<String, String> dto = new HashMap<String, String>();
|
|
|
- //必填
|
|
|
+ //ffmpeg程序路径
|
|
|
+// dto.put("ffmpeg_path", "D:\\workSoftWare\\ffmpeg\\bin\\ffmpeg.exe");
|
|
|
dto.put("ffmpeg_path", ffmepgPath);
|
|
|
- //必填
|
|
|
+ logger.info("ffmepg程序路径:" + ffmepgPath);
|
|
|
+ //视频输入路径
|
|
|
dto.put("input_path", fileUrl);
|
|
|
+ logger.info("输入文件路径:" + fileUrl);
|
|
|
// dto.put("input_path", "D:\\WorkSpace\\file\\video.mp4");
|
|
|
- //必填
|
|
|
+ //视频输出路径
|
|
|
dto.put("video_converted_path", filePath);
|
|
|
+ // 白名单
|
|
|
+ dto.put("whitelist", "file,http,https,rtp,udp,tcp,tls");
|
|
|
//可选(注意windows下面的logo地址前面要写4个反斜杠,如果用浏览器里面调用servlet并传参只用两个,如 d:\\:/ffmpeg/input/logo.png)
|
|
|
try {
|
|
|
- ClassPathResource classPathResource = new ClassPathResource("/templates/images/imgWaterMark.png");
|
|
|
- dto.put("logo", classPathResource.getURL().toString());
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("/templates/images/caimeiLogo2.png");
|
|
|
+ String logoPath = classPathResource.getURL().toString();
|
|
|
+ if (!StringUtils.isEmpty(logoPath) && logoPath.startsWith("file:/D:")) {
|
|
|
+ logoPath = logoPath.replace("file:/D", "D\\\\");
|
|
|
+ }
|
|
|
+ dto.put("logo", logoPath);
|
|
|
+ logger.info("视频水印图片路径:"+logoPath);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -177,6 +196,8 @@ public class FFMPEG {
|
|
|
Map<String, String> map = new HashMap<>(2);
|
|
|
List<String> cmd = new ArrayList<String>();
|
|
|
cmd.add(dto.get("ffmpeg_path"));
|
|
|
+ cmd.add("-protocol_whitelist");
|
|
|
+ cmd.add(dto.get("whitelist"));
|
|
|
cmd.add("-i");
|
|
|
cmd.add(dto.get("input_path"));
|
|
|
String height = "";
|