Aslee 3 年之前
父節點
當前提交
9de3620abf

+ 28 - 7
src/main/java/com/caimei/modules/archive/utils/FFMPEG.java

@@ -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 = "";

+ 10 - 0
src/main/java/com/caimei/modules/archive/web/CmProductArchiveContentController.java

@@ -4,6 +4,8 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.caimei.modules.archive.entity.CmProductArchiveFile;
+import com.caimei.modules.archive.utils.FFMPEG;
+import com.caimei.modules.archive.utils.WaterMarkUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -108,4 +110,12 @@ public class CmProductArchiveContentController extends BaseController {
     public Map<String, Object> addWaterMark(@RequestParam("file") MultipartFile file, @RequestParam("fileName") String fileName) {
         return cmProductArchiveContentService.addWaterMark(file, fileName);
     }
+
+    @ResponseBody
+    @RequestMapping(value = "getVideoSize")
+    public Map<String, Object> getVideoSize( String fileUrl) {
+        return FFMPEG.setVideoWaterMark(fileUrl, "/mnt/newdatadrive/data/runtime/tomcat-instance/manager/tempFile/testVideo.mp4");
+    }
+
+
 }

+ 27 - 7
src/main/webapp/WEB-INF/views/modules/hehe/cmHeheCouponForm.jsp

@@ -15,12 +15,12 @@
 			//$("#name").focus();
 			$("#inputForm").validate({
 				submitHandler: function(form){
-                    var productType = $("#productType").val() * 1;
+					var productType = $("input[name='productType']:checked").val() * 1;
                     if (productType === 2 && imageList.length <= 0) {
                         alertx("请先添加商品");
                         return false;
                     }
-                    var couponType = $("couponType").val() * 1;
+                    var couponType = $("#couponType").val() * 1;
                     if (couponType === 2 && userList.length <= 0) {
                         alertx("请先添加用户");
                         return false;
@@ -44,8 +44,8 @@
 					var permanentFlag = $("#permanentFlag").val() * 1;
 					var startTime = $("#startTime").val();
 					var endTime = $("#endTime").val();
-					if (startNowFlag === 1) {
-						startTime = new Date();
+					if (startNowFlag === 1 && startTime == '') {
+						startTime = new Date().format("yyyy-MM-dd hh:mm");
 					}
 					if (permanentFlag === 0 && startTime >= endTime) {
 						alertx("下架时间不能早于上架时间");
@@ -66,6 +66,27 @@
 			});
 		});
 
+		Date.prototype.format = function(fmt) {
+			var o = {
+				"M+" : this.getMonth()+1,                 //月份
+				"d+" : this.getDate(),                    //日
+				"h+" : this.getHours(),                   //小时
+				"m+" : this.getMinutes(),                 //分
+				"s+" : this.getSeconds(),                 //秒
+				"q+" : Math.floor((this.getMonth()+3)/3), //季度
+				"S"  : this.getMilliseconds()             //毫秒
+			};
+			if(/(y+)/.test(fmt)) {
+				fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
+			}
+			for(var k in o) {
+				if(new RegExp("("+ k +")").test(fmt)){
+					fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
+				}
+			}
+			return fmt;
+		}
+
 		/**
 		 * @param obj
 		 * jquery控制input只能输入数字
@@ -116,7 +137,7 @@
 			<label class="control-label"><font color="red">*</font>上架时间:</label>
 			<div class="controls">
 				<input id="startTime" name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
-					value="<fmt:formatDate value="${cmHeheCoupon.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
+					value="<fmt:formatDate value="${cmHeheCoupon.startTime}" pattern="yyyy-MM-dd HH:mm"/>"
 					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
 				<input type="checkbox" id="startNowFlag" name="startNowFlag" class="formCheck" value="${cmHeheCoupon.startNowFlag eq 1?1:0}" ${cmHeheCoupon.startNowFlag eq 1 ? "checked" : ""} onclick="changeCondition('startNowFlag','startTime')" />立即上架
                 <input id="startTimeTemp" type="hidden" value="${cmHeheCoupon.startTime}">
@@ -126,7 +147,7 @@
 			<label class="control-label"><font color="red">*</font>下架时间:</label>
 			<div class="controls">
 				<input id="endTime" name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
-					value="<fmt:formatDate value="${cmHeheCoupon.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
+					value="<fmt:formatDate value="${cmHeheCoupon.endTime}" pattern="yyyy-MM-dd HH:mm"/>"
 					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
 				<input type="checkbox" id="permanentFlag" name="permanentFlag" class="formCheck" value="${cmHeheCoupon.permanentFlag eq 1?1:0}" ${cmHeheCoupon.permanentFlag eq 1 ? "checked" : ""}
 					   onclick="changeCondition('permanentFlag','endTime')" />永久
@@ -362,7 +383,6 @@
 	}
 
 	function initInputDisplay() {
-		debugger
 		var noThresholdFlag = $("#noThresholdFlag").val();
 		var startNowFlag = $("#startNowFlag").val();
 		var permanentFlag = $("#permanentFlag").val();

+ 2 - 2
src/main/webapp/WEB-INF/views/modules/hehe/cmHeheDiscountForm.jsp

@@ -10,8 +10,8 @@
 			//$("#name").focus();
 			$("#inputForm").validate({
 				submitHandler: function(form){
-					var productType = $("#productType").val() * 1;
-					if (productType === 2 && imageList.length <= 0) {
+                    var productType = $("input[name='productType']:checked").val() * 1;
+                    if (productType === 2 && imageList.length <= 0) {
 						alertx("请先添加商品");
 						return false;
 					}