Commit ecb6f988bb8395f33ebba80ea69a28a9d681acc9
1 parent
b002079b
添加抽帧部分信息
Showing
6 changed files
with
278 additions
and
20 deletions
src/main/java/com/cnlive/shenhe/api/AvsampleCallBackControllerApi.java
0 → 100644
| 1 | +package com.cnlive.shenhe.api; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.cnlive.shenhe.entity.ShyVideos; | |
| 5 | +import com.cnlive.shenhe.serviceImpl.VideosServiceImpl; | |
| 6 | +import com.cnlive.shenhe.utils.CommonConst; | |
| 7 | +import com.cnlive.shenhe.utils.CommonUtils; | |
| 8 | +import org.slf4j.Logger; | |
| 9 | +import org.slf4j.LoggerFactory; | |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | +import org.springframework.stereotype.Controller; | |
| 12 | +import org.springframework.web.bind.annotation.PostMapping; | |
| 13 | +import org.springframework.web.bind.annotation.RequestBody; | |
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 15 | + | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * @Auther: 周伟鹏 | |
| 20 | + * @Date: 2018/12/21 13:43 | |
| 21 | + * @Description:抽帧回调接口 | |
| 22 | + */ | |
| 23 | +@Controller | |
| 24 | +@RequestMapping("/api/avsample") | |
| 25 | +public class AvsampleCallBackControllerApi { | |
| 26 | + | |
| 27 | + private static Logger logger = LoggerFactory.getLogger(AvsampleCallBackControllerApi.class); | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + VideosServiceImpl videosService; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 接收抽帧结果 | |
| 34 | + * @param json | |
| 35 | + */ | |
| 36 | + @PostMapping("/callback") | |
| 37 | + public void callback(@RequestBody JSONObject json) { | |
| 38 | + logger.info("抽帧回调请求。。。。json=="+json.toJSONString()); | |
| 39 | + String taskId = json.getString("taskId"); | |
| 40 | + if(CommonUtils.isNotEmpty(taskId)){ | |
| 41 | + ShyVideos shyVideo = new ShyVideos(); | |
| 42 | + shyVideo.setTask_id(taskId); | |
| 43 | + List<ShyVideos> shyVideosList = videosService.findshyVideo(shyVideo); | |
| 44 | + if(!shyVideosList.isEmpty()){ | |
| 45 | + ShyVideos video = shyVideosList.get(0); | |
| 46 | + Integer code = json.getInteger("code"); | |
| 47 | + if(code==3){ | |
| 48 | + video.setAvsample(CommonConst.AVSAMPLE_SUCCESS); | |
| 49 | + video.setAvsample_imgs(json.getJSONArray("images").toJSONString()); | |
| 50 | + }else{ | |
| 51 | + video.setAvsample(CommonConst.AVSAMPLE_FAIL); | |
| 52 | + } | |
| 53 | + video.setAvsample_msg(json.toJSONString()); | |
| 54 | + videosService.updateshyVideos(video); | |
| 55 | + } | |
| 56 | + | |
| 57 | + } | |
| 58 | + } | |
| 59 | +} | ... | ... |
src/main/java/com/cnlive/shenhe/api/VideosControllerApi.java
| 1 | 1 | package com.cnlive.shenhe.api; |
| 2 | 2 | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 3 | 4 | import com.alibaba.fastjson.JSONObject; |
| 4 | 5 | import com.cnlive.shenhe.bean.ErrorEnum; |
| 5 | 6 | import com.cnlive.shenhe.bean.ResponseBean; |
| 6 | 7 | import com.cnlive.shenhe.entity.ShyVideos; |
| 7 | 8 | import com.cnlive.shenhe.serviceImpl.UsersServiceImpl; |
| 8 | 9 | import com.cnlive.shenhe.serviceImpl.VideosServiceImpl; |
| 9 | -import com.cnlive.shenhe.utils.AuditPass; | |
| 10 | -import com.cnlive.shenhe.utils.CommonConst; | |
| 11 | -import com.cnlive.shenhe.utils.CommonUtils; | |
| 10 | +import com.cnlive.shenhe.utils.*; | |
| 11 | +import com.sun.org.apache.bcel.internal.generic.NEW; | |
| 12 | 12 | import org.slf4j.Logger; |
| 13 | 13 | import org.slf4j.LoggerFactory; |
| 14 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import org.springframework.beans.factory.annotation.Value; | |
| 15 | 16 | import org.springframework.stereotype.Controller; |
| 16 | 17 | import org.springframework.web.bind.annotation.PostMapping; |
| 17 | 18 | import org.springframework.web.bind.annotation.RequestMapping; |
| 18 | 19 | import org.springframework.web.bind.annotation.ResponseBody; |
| 19 | 20 | |
| 21 | +import java.util.Date; | |
| 22 | +import java.util.HashMap; | |
| 20 | 23 | import java.util.List; |
| 24 | +import java.util.Map; | |
| 21 | 25 | |
| 22 | 26 | /** |
| 23 | 27 | * @Auther: chenhao |
| ... | ... | @@ -35,6 +39,25 @@ public class VideosControllerApi { |
| 35 | 39 | @Autowired |
| 36 | 40 | UsersServiceImpl usersService; |
| 37 | 41 | |
| 42 | + @Value("${avsmple_appkey}") | |
| 43 | + String appkey; | |
| 44 | + | |
| 45 | + @Value("${avsmple_url}") | |
| 46 | + String url; | |
| 47 | + | |
| 48 | + @Value("${avsmple_callback}") | |
| 49 | + String callback; | |
| 50 | + | |
| 51 | + @Value("${qn_bucket}") | |
| 52 | + String qn_bucket; | |
| 53 | + | |
| 54 | + @Value("${ks_bucket}") | |
| 55 | + String ks_bucket; | |
| 56 | + | |
| 57 | + @Value("${desdir}") | |
| 58 | + String desdir; | |
| 59 | + | |
| 60 | + | |
| 38 | 61 | @PostMapping("/import") |
| 39 | 62 | @ResponseBody |
| 40 | 63 | public ResponseBean impotVideo(String param) { |
| ... | ... | @@ -64,8 +87,10 @@ public class VideosControllerApi { |
| 64 | 87 | shyVideos.setVideo_upload_time(json.getDate(" uploadTime")); |
| 65 | 88 | shyVideos.setVideo_priority(json.getString("priority")); |
| 66 | 89 | shyVideos.setCallback(json.getString("callback")); |
| 67 | - shyVideos.setSpid(Integer.parseInt(json.getString("spId"))); | |
| 90 | + shyVideos.setSpid(json.getInteger("spId")); | |
| 68 | 91 | shyVideos.setState(CommonConst.AUDIT_INTT); |
| 92 | + shyVideos1.setBucket(json.getString("bucketName")); | |
| 93 | + shyVideos1.setPlat(json.getInteger("bucketType")); | |
| 69 | 94 | boolean YorN = videosService.updateshyVideos(shyVideos); |
| 70 | 95 | if (YorN == true) { |
| 71 | 96 | return new ResponseBean(ErrorEnum.SUCCESS); |
| ... | ... | @@ -88,8 +113,11 @@ public class VideosControllerApi { |
| 88 | 113 | shyVideos1.setVideo_upload_time(json.getDate("uploadTime")); |
| 89 | 114 | shyVideos1.setVideo_priority(json.getString("priority")); |
| 90 | 115 | shyVideos1.setCallback(json.getString("callback")); |
| 91 | - shyVideos1.setSpid(Integer.parseInt(json.getString("spId"))); | |
| 116 | + shyVideos1.setSpid(json.getInteger("spId")); | |
| 92 | 117 | shyVideos1.setState(CommonConst.AUDIT_INTT); |
| 118 | + shyVideos1.setBucket(json.getString("bucketName")); | |
| 119 | + shyVideos1.setPlat(json.getInteger("bucketType")); | |
| 120 | + | |
| 93 | 121 | boolean result = videosService.impotVideo(shyVideos1); |
| 94 | 122 | if (result == true) { |
| 95 | 123 | return new ResponseBean(ErrorEnum.SUCCESS); |
| ... | ... | @@ -97,4 +125,65 @@ public class VideosControllerApi { |
| 97 | 125 | return new ResponseBean(ErrorEnum.ERROR); |
| 98 | 126 | } |
| 99 | 127 | } |
| 128 | + | |
| 129 | + /** | |
| 130 | + * 申请抽帧 | |
| 131 | + * @param video | |
| 132 | + * @return | |
| 133 | + */ | |
| 134 | + public ShyVideos avsample(ShyVideos video) { | |
| 135 | + try { | |
| 136 | + JSONObject params = new JSONObject(); | |
| 137 | + String video_url = video.getVideo_url(); | |
| 138 | + Integer plat = video.getPlat(); | |
| 139 | + String bucket = video.getBucket(); | |
| 140 | + Integer spid = video.getSpid(); | |
| 141 | + | |
| 142 | + JSONObject attach = new JSONObject(); | |
| 143 | + attach.put("num",24); | |
| 144 | + if (CommonConst.KS_PLAT == plat) { | |
| 145 | + //金山 | |
| 146 | + params.put("plat", 0); | |
| 147 | + params.put("dstBucket",ks_bucket); | |
| 148 | + } else if (CommonConst.QINIU_PLAT == plat) { | |
| 149 | + //七牛 | |
| 150 | + params.put("plat", 1); | |
| 151 | + params.put("dstBucket",qn_bucket); | |
| 152 | + } | |
| 153 | + String path = video_url.replace("//", ""); | |
| 154 | + path = "/" + bucket + path.substring(path.indexOf("/"), path.length()); | |
| 155 | + String dstDir = desdir+"/"+spid+"/"+CommonUtils.getCurrentDate("yyyy/MM/dd"); | |
| 156 | + String formats = video_url.substring(video_url.indexOf(".")+1); | |
| 157 | + params.put("path",path); | |
| 158 | + params.put("dstDir",dstDir); | |
| 159 | + params.put("type","avsample"); | |
| 160 | + params.put("formats",formats.toLowerCase()); | |
| 161 | + params.put("spId",spid); | |
| 162 | + params.put("cbUrl",callback); | |
| 163 | + params.put("attach",attach); | |
| 164 | + | |
| 165 | + HashMap<String, String> dataMap = new HashMap<>(); | |
| 166 | + dataMap.put("timestamp", new Date().getTime() / 1000 + ""); | |
| 167 | + dataMap.put("params",params.toJSONString()); | |
| 168 | + String httpUrl = OpenUtil.buildURL(url, dataMap, appkey); | |
| 169 | + logger.info("抽帧请求httpUrl===" + httpUrl); | |
| 170 | + Map<String, String> resultMap = HttpUtil.init().post(httpUrl); | |
| 171 | + JSONObject result = JSON.parseObject(resultMap.get("result")); | |
| 172 | + Integer code = result.getInteger("code"); | |
| 173 | + if(code==0){ | |
| 174 | + video.setAvsample(CommonConst.AVSAMPLE_ING); | |
| 175 | + }else{ | |
| 176 | + video.setAvsample(CommonConst.AVSAMPLE_FAIL); | |
| 177 | + } | |
| 178 | + video.setTask_id(result.getString("taskId")); | |
| 179 | + video.setAvsample_msg(result.toJSONString()); | |
| 180 | + } catch (Exception e) { | |
| 181 | + logger.error("请求抽帧失败,video_id:{}", video.getVideo_id(), e); | |
| 182 | + video.setAvsample(CommonConst.AVSAMPLE_FAIL); | |
| 183 | + } | |
| 184 | + return video; | |
| 185 | + } | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 100 | 189 | } | ... | ... |
src/main/java/com/cnlive/shenhe/entity/ShyVideos.java
| ... | ... | @@ -96,9 +96,9 @@ public class ShyVideos { |
| 96 | 96 | private String receive_user_id; |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | - * 是否抽帧 | |
| 99 | + * 抽帧状态:0:未抽帧;1:抽帧中;2:抽帧成功;3:抽帧失败 | |
| 100 | 100 | */ |
| 101 | - private Boolean avsample; | |
| 101 | + private Integer avsample; | |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * 抽帧图片地址 |
| ... | ... | @@ -111,11 +111,34 @@ public class ShyVideos { |
| 111 | 111 | private String avsample_msg; |
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | + * 抽帧请求标记 | |
| 115 | + */ | |
| 116 | + private String task_id; | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * 视频存储所在的bucket | |
| 120 | + */ | |
| 121 | + private String bucket; | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * 视频存放位置1:金山;2:七牛 | |
| 125 | + */ | |
| 126 | + private Integer plat; | |
| 127 | + | |
| 128 | + /** | |
| 114 | 129 | * 审核员 |
| 115 | 130 | */ |
| 116 | 131 | @Transient |
| 117 | 132 | private String auditor; |
| 118 | 133 | |
| 134 | + public String getAuditor() { | |
| 135 | + return auditor; | |
| 136 | + } | |
| 137 | + | |
| 138 | + public void setAuditor(String auditor) { | |
| 139 | + this.auditor = auditor; | |
| 140 | + } | |
| 141 | + | |
| 119 | 142 | /** |
| 120 | 143 | * @return id |
| 121 | 144 | */ |
| ... | ... | @@ -471,20 +494,20 @@ public class ShyVideos { |
| 471 | 494 | } |
| 472 | 495 | |
| 473 | 496 | /** |
| 474 | - * 获取是否抽帧 | |
| 497 | + * 获取抽帧状态:0:未抽帧;1:抽帧中;2:抽帧成功;3:抽帧失败 | |
| 475 | 498 | * |
| 476 | - * @return avsample - 是否抽帧 | |
| 499 | + * @return avsample - 抽帧状态:0:未抽帧;1:抽帧中;2:抽帧成功;3:抽帧失败 | |
| 477 | 500 | */ |
| 478 | - public Boolean getAvsample() { | |
| 501 | + public Integer getAvsample() { | |
| 479 | 502 | return avsample; |
| 480 | 503 | } |
| 481 | 504 | |
| 482 | 505 | /** |
| 483 | - * 设置是否抽帧 | |
| 506 | + * 设置抽帧状态:0:未抽帧;1:抽帧中;2:抽帧成功;3:抽帧失败 | |
| 484 | 507 | * |
| 485 | - * @param avsample 是否抽帧 | |
| 508 | + * @param avsample 抽帧状态:0:未抽帧;1:抽帧中;2:抽帧成功;3:抽帧失败 | |
| 486 | 509 | */ |
| 487 | - public void setAvsample(Boolean avsample) { | |
| 510 | + public void setAvsample(Integer avsample) { | |
| 488 | 511 | this.avsample = avsample; |
| 489 | 512 | } |
| 490 | 513 | |
| ... | ... | @@ -524,11 +547,57 @@ public class ShyVideos { |
| 524 | 547 | this.avsample_msg = avsample_msg; |
| 525 | 548 | } |
| 526 | 549 | |
| 527 | - public String getAuditor() { | |
| 528 | - return auditor; | |
| 550 | + /** | |
| 551 | + * 获取抽帧请求标记 | |
| 552 | + * | |
| 553 | + * @return task_id - 抽帧请求标记 | |
| 554 | + */ | |
| 555 | + public String getTask_id() { | |
| 556 | + return task_id; | |
| 529 | 557 | } |
| 530 | 558 | |
| 531 | - public void setAuditor(String auditor) { | |
| 532 | - this.auditor = auditor; | |
| 559 | + /** | |
| 560 | + * 设置抽帧请求标记 | |
| 561 | + * | |
| 562 | + * @param task_id 抽帧请求标记 | |
| 563 | + */ | |
| 564 | + public void setTask_id(String task_id) { | |
| 565 | + this.task_id = task_id; | |
| 566 | + } | |
| 567 | + | |
| 568 | + /** | |
| 569 | + * 获取视频存储所在的bucket | |
| 570 | + * | |
| 571 | + * @return bucket - 视频存储所在的bucket | |
| 572 | + */ | |
| 573 | + public String getBucket() { | |
| 574 | + return bucket; | |
| 575 | + } | |
| 576 | + | |
| 577 | + /** | |
| 578 | + * 设置视频存储所在的bucket | |
| 579 | + * | |
| 580 | + * @param bucket 视频存储所在的bucket | |
| 581 | + */ | |
| 582 | + public void setBucket(String bucket) { | |
| 583 | + this.bucket = bucket; | |
| 584 | + } | |
| 585 | + | |
| 586 | + /** | |
| 587 | + * 获取视频存放位置1:金山;2:七牛 | |
| 588 | + * | |
| 589 | + * @return plat - 视频存放位置1:金山;2:七牛 | |
| 590 | + */ | |
| 591 | + public Integer getPlat() { | |
| 592 | + return plat; | |
| 593 | + } | |
| 594 | + | |
| 595 | + /** | |
| 596 | + * 设置视频存放位置1:金山;2:七牛 | |
| 597 | + * | |
| 598 | + * @param plat 视频存放位置1:金山;2:七牛 | |
| 599 | + */ | |
| 600 | + public void setPlat(Integer plat) { | |
| 601 | + this.plat = plat; | |
| 533 | 602 | } |
| 534 | 603 | } |
| 535 | 604 | \ No newline at end of file | ... | ... |
src/main/java/com/cnlive/shenhe/utils/CommonConst.java
| ... | ... | @@ -55,4 +55,31 @@ public class CommonConst { |
| 55 | 55 | |
| 56 | 56 | public static JSONObject BUSINESS = JSONObject.parseObject("{\"1\":\"点播业务\",\"2\":\"评论业务\"}"); |
| 57 | 57 | |
| 58 | + /** | |
| 59 | + * 抽帧状态:未抽帧 | |
| 60 | + */ | |
| 61 | + public static Integer AVSAMPLE_INTIT = 0; | |
| 62 | + /** | |
| 63 | + * 抽帧状态:抽帧中 | |
| 64 | + */ | |
| 65 | + public static Integer AVSAMPLE_ING = 1; | |
| 66 | + /** | |
| 67 | + * 抽帧状态:抽帧完成 | |
| 68 | + */ | |
| 69 | + public static Integer AVSAMPLE_SUCCESS = 2; | |
| 70 | + /** | |
| 71 | + * 抽帧状态:抽帧失败 | |
| 72 | + */ | |
| 73 | + public static Integer AVSAMPLE_FAIL = 3; | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 金山标记 | |
| 77 | + */ | |
| 78 | + public static Integer KS_PLAT = 1; | |
| 79 | + /** | |
| 80 | + * 七牛标记 | |
| 81 | + */ | |
| 82 | + public static Integer QINIU_PLAT = 2; | |
| 83 | + | |
| 84 | + | |
| 58 | 85 | } | ... | ... |
src/main/resources/application.properties
| ... | ... | @@ -36,5 +36,16 @@ url=http://mam.innerapi.cnlive.com/v1/inner/ShenHeInfo/shenheNotify |
| 36 | 36 | platformKey =AUDIT |
| 37 | 37 | platformValue=10011438 |
| 38 | 38 | |
| 39 | -#评论回调地址 | |
| 40 | -commenturl=http://comment.cnlive.com/services/commentForHd/auditCallBack | |
| 41 | 39 | \ No newline at end of file |
| 40 | +#抽帧常量 | |
| 41 | +avsmple_appkey=6962df5e02d846f490d64f3a68ac89fc | |
| 42 | +avsmple_url=http://transcode.cnlive.com/api/request | |
| 43 | +avsmple_callback=http://test.shen.cnlive.com/api/avsample/callback | |
| 44 | + | |
| 45 | +#抽帧存放bucket和域名 | |
| 46 | +qn_bucket=cnlivetest | |
| 47 | +qn_domain=http://test.qnvod.cnlive.com | |
| 48 | +ks_bucket=cnlive-test | |
| 49 | +ks_domain=http://test.wideo.cnlive.com | |
| 50 | + | |
| 51 | +#图片存放根路径 | |
| 52 | +desdir=shen | ... | ... |
src/main/resources/mapper/ShyVideosMapper.xml
| ... | ... | @@ -26,8 +26,11 @@ |
| 26 | 26 | <result column="updated_at" jdbcType="TIMESTAMP" property="updated_at" /> |
| 27 | 27 | <result column="receive" jdbcType="BIT" property="receive" /> |
| 28 | 28 | <result column="receive_user_id" jdbcType="VARCHAR" property="receive_user_id" /> |
| 29 | - <result column="avsample" jdbcType="BIT" property="avsample" /> | |
| 29 | + <result column="avsample" jdbcType="INTEGER" property="avsample" /> | |
| 30 | 30 | <result column="avsample_imgs" jdbcType="VARCHAR" property="avsample_imgs" /> |
| 31 | 31 | <result column="avsample_msg" jdbcType="VARCHAR" property="avsample_msg" /> |
| 32 | + <result column="task_id" jdbcType="VARCHAR" property="task_id" /> | |
| 33 | + <result column="bucket" jdbcType="VARCHAR" property="bucket" /> | |
| 34 | + <result column="plat" jdbcType="INTEGER" property="plat" /> | |
| 32 | 35 | </resultMap> |
| 33 | 36 | </mapper> |
| 34 | 37 | \ No newline at end of file | ... | ... |