Authored by mali

转码

... ... @@ -44,7 +44,7 @@ public class QNliveUtil {
public static String MP4_FILEKEY_PRE = "ufo/live/mp4/"; // mp4文件路径
private static String FETCH_URL_PRE = "http://yoho-live-down.yohobuy.com/"; // 获取直播流的url
// private static String FETCH_URL_PRE = "http://yoho-live-down.yohobuy.com/"; // 获取直播流的url
private static String FOPS_PARAMS = "avthumb/mp4/s/1280x720/vb/2m/an/1/hr/0/r/30"; // 转码参数1280×720
... ... @@ -63,12 +63,12 @@ public class QNliveUtil {
/**
* 抓取直播流
* @param fileKey 保存流的文件名
* @param cameraIdentify 摄像头标识 北京还是南京
* @param liveM3u8Url 摄像头标识 北京还是南京
* @param startTime 摄像开始时间
* @param endTime 摄像结束时间
*/
public void fetch(String fileKey, Integer cameraIdentify, String startTime, String endTime) throws PlatformException {
logger.info("bucketManager.fetch begin fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, cameraIdentify, startTime, endTime);
public void fetch(String fileKey, String liveM3u8Url, String startTime, String endTime) throws PlatformException {
logger.info("bucketManager.fetch begin fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, liveM3u8Url, startTime, endTime);
//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, cfg);
... ... @@ -77,12 +77,7 @@ public class QNliveUtil {
String key = FILEKEY_PRE + fileKey + ".m3u8"; // 例如 "ufo/live/m3u8/yohotest15.m3u8";
//要fetch的url "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1544425260&endtime=1544425440";
String fetchUrl = null;
if (Integer.valueOf(1).equals(cameraIdentify)) { // 南京的鉴定中心对应的摄像头视频URL
fetchUrl = FETCH_URL_PRE + "yoho13/yoho.m3u8" + "?starttime=" + startTime + "&endtime=" + endTime;
} else if (Integer.valueOf(0).equals(cameraIdentify)){ // 北京的鉴定中心对应的摄像头视频URL
fetchUrl = FETCH_URL_PRE + "yoho13/yoho.m3u8" + "?starttime=" + startTime + "&endtime=" + endTime;
}
String fetchUrl = liveM3u8Url + "?starttime=" + startTime + "&endtime=" + endTime;
logger.info("bucketManager.fetch before fetchUrl is {}", fetchUrl);
... ... @@ -96,7 +91,7 @@ public class QNliveUtil {
logger.info("Resp is {} from bucketManager.fetch", fetch.key);
} catch (QiniuException e) {
logger.error("bucketManager.fetch find wrong fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, cameraIdentify, startTime, endTime, e.response);
logger.error("bucketManager.fetch find wrong fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, liveM3u8Url, startTime, endTime, e.response);
throw new PlatformException(400);
}
... ...
package com.yoho.order.dal;
import com.yoho.order.model.CameraRecord;
import java.util.List;
/**
* Created by li.ma on 2018/12/19.
*/
public interface CameraRecordMapper {
List<CameraRecord> queryAllCameraRecord();
}
... ...
package com.yoho.order.model;
import com.alibaba.fastjson.JSONObject;
/**
* Created by li.ma on 2018/12/19.
*/
public class CameraRecord {
private Integer id;
private Integer cameraCode;
private String cameraName;
private String vedioFileUrl;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCameraCode() {
return cameraCode;
}
public void setCameraCode(Integer cameraCode) {
this.cameraCode = cameraCode;
}
public String getCameraName() {
return cameraName;
}
public void setCameraName(String cameraName) {
this.cameraName = cameraName;
}
public String getVedioFileUrl() {
return vedioFileUrl;
}
public void setVedioFileUrl(String vedioFileUrl) {
this.vedioFileUrl = vedioFileUrl;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
}
... ...
... ... @@ -39,6 +39,16 @@ public class QiniuLiveRecord {
private Integer notInId;
private Integer cameraCode;
public Integer getCameraCode() {
return cameraCode;
}
public void setCameraCode(Integer cameraCode) {
this.cameraCode = cameraCode;
}
public Integer getNotInId() {
return notInId;
}
... ...
... ... @@ -19,10 +19,11 @@
<result column="goods_id" property="goodsId" jdbcType="INTEGER" />
<result column="product_id" property="productId" jdbcType="INTEGER" />
<result column="show_flag" property="showFlag" jdbcType="INTEGER" />
<result column="camera_code" property="cameraCode" javaType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, order_code, skup, seller_order_code, depot_no, start_time, end_time, persist_id,
vedio_file_url, create_time, update_time, pid, status, storage_id, goods_id, product_id, show_flag
vedio_file_url, create_time, update_time, pid, status, storage_id, goods_id, product_id, show_flag, camera_code
</sql>
<select id="selectByOrderCodes" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -39,12 +40,12 @@
seller_order_code, depot_no, start_time,
end_time, persist_id, vedio_file_url,
create_time, pid,
status)
status, camera_code)
values (#{orderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER},
#{sellerOrderCode,jdbcType=BIGINT}, #{depotNo,jdbcType=INTEGER}, #{startTime,jdbcType=INTEGER},
#{endTime,jdbcType=INTEGER}, #{persistId,jdbcType=VARCHAR}, #{vedioFileUrl,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER},
#{status,jdbcType=INTEGER})
#{status,jdbcType=INTEGER}, #{cameraCode, jdbcType=INTEGER})
</insert>
<update id="updateProductBySkup" parameterType="com.yoho.order.model.QiniuLiveRecord" >
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.order.service.impl.UfoLiveService;
import com.yoho.ufo.service.model.ApiResponse;
import com.yohobuy.ufo.model.order.req.QNliveReq;
import com.yohobuy.ufo.model.order.resp.CameraRecordResp;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -11,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by li.ma on 2018/12/13.
*/
... ... @@ -59,4 +62,14 @@ public class UfoLiveController {
return new ApiResponse.ApiResponseBuilder().code(200).data(fileUrl).message("查询成功").build();
}
@RequestMapping(value = "/queryCameraRecord")
public ApiResponse queryCameraRecord(QNliveReq req) {
LOGGER.info("queryCameraRecord in. req is {}", req);
List<CameraRecordResp> cameraRecordResps = ufoLiveService.queryCameraRecord(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(cameraRecordResps).message("查询成功").build();
}
}
... ...
... ... @@ -2,7 +2,9 @@ package com.yoho.ufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.order.dal.CameraRecordMapper;
import com.yoho.order.dal.QiniuLiveRecordMapper;
import com.yoho.order.model.CameraRecord;
import com.yoho.order.model.QiniuLiveRecord;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.order.service.event.QiniuLiveRecordEvent;
... ... @@ -11,6 +13,7 @@ import com.yoho.ufo.service.impl.UserHelper;
import com.yoho.ufo.util.DateUtil;
import com.yohobuy.ufo.model.order.req.QNliveReq;
import com.yohobuy.ufo.model.order.resp.CameraRecordResp;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -20,6 +23,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
... ... @@ -37,6 +41,9 @@ public class UfoLiveService implements ApplicationContextAware {
private ApplicationContext context;
@Autowired
private CameraRecordMapper cameraRecordMapper;
public void setApplicationContext(ApplicationContext applicationContext) {
this.context = applicationContext;
}
... ... @@ -47,7 +54,9 @@ public class UfoLiveService implements ApplicationContextAware {
String fileName = String.valueOf(req.getOrderCode()) + "_" + String.valueOf(req.getStartTime());
qNliveUtil.fetch(fileName, req.getDepotNo(), String.valueOf(req.getStartTime()), String.valueOf(req.getEndTime()));
String m3u8Url = queryM3u8Url(req.getCameraCode());
qNliveUtil.fetch(fileName, m3u8Url, String.valueOf(req.getStartTime()), String.valueOf(req.getEndTime()));
String persistId = qNliveUtil.transfer(fileName, fileName);
... ... @@ -74,6 +83,7 @@ public class UfoLiveService implements ApplicationContextAware {
record.setStartTime(req.getStartTime());
record.setStatus(0);
record.setVedioFileUrl(fileName + ".mp4");
record.setCameraCode(req.getCameraCode());
qiniuLiveRecordMapper.insert(record);
record.setNotInId(record.getId());
... ... @@ -105,4 +115,24 @@ public class UfoLiveService implements ApplicationContextAware {
//http://yhb-img01.qiniudn.com/ufo/live/mp4/9817910304768_1544775266.mp4
return QNliveUtil.LIVE_VEDIO_DOMAIN + QNliveUtil.MP4_FILEKEY_PRE + qiniuLiveRecord.getVedioFileUrl();
}
public String queryM3u8Url(Integer cameraCode) throws PlatformException {
List<CameraRecord> cameraRecordList = cameraRecordMapper.queryAllCameraRecord();
for (CameraRecord item : cameraRecordList) {
if (item.getCameraCode().equals(cameraCode)) {
return item.getVedioFileUrl();
}
}
throw new PlatformException(400);
}
public List<CameraRecordResp> queryCameraRecord(QNliveReq req) {
List<CameraRecord> cameraRecordList = cameraRecordMapper.queryAllCameraRecord();
List<CameraRecordResp> cameraRecordResps = new ArrayList<>();
cameraRecordList.stream().forEach(item -> cameraRecordResps.add(new CameraRecordResp(item.getCameraCode(), item.getCameraName())));
return cameraRecordResps;
}
}
... ...
... ... @@ -726,6 +726,7 @@ function addRecordPage(skup, order_code, id) {
id : id,
skup : skup,
orderCode : order_code,
cameraCode : $('#cameraCode').val(),
startTime : $('#startTime').val(),
endTime : $('#endTime').val(),
depotNo: $("#depotNo").combobox("getValue")
... ...
... ... @@ -10,6 +10,9 @@
<ul>
<li>
<input id="cameraCode" type="text"/>
</li>
<li>
计时&nbsp;:&nbsp;<input id='txt' type='text'/>
</li>
<li>
... ... @@ -17,34 +20,56 @@
</li>
</ul>
<script type="text/javascript">
var c=0
var t
if (t) {
clearTimeout(t);
}
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}
var totalVar;
function stopCount()
{
var endTime = $('#endTime').val();
var startTime = $('#startTime').val();
var secondVar = parseInt((endTime - startTime) % 60);
if (endTime - startTime > 60) {
var minuteVar = parseInt((endTime - startTime) / 60);
totalVar = minuteVar + '分' + secondVar + '秒';
} else {
totalVar = secondVar + '秒';
$(function () {
var c = 0
var t
if (t) {
clearTimeout(t);
}
function timedCount() {
document.getElementById('txt').value = c
c = c + 1
t = setTimeout("timedCount()", 1000)
}
var totalVar;
function stopCount() {
var endTime = $('#endTime').val();
var startTime = $('#startTime').val();
var secondVar = parseInt((endTime - startTime) % 60);
if (endTime - startTime > 60) {
var minuteVar = parseInt((endTime - startTime) / 60);
totalVar = minuteVar + '分' + secondVar + '秒';
} else {
totalVar = secondVar + '秒';
}
c = 0;
setTimeout("document.getElementById('total').value=totalVar", 0);
clearTimeout(t);
}
c=0;
setTimeout("document.getElementById('total').value=totalVar", 0);
clearTimeout(t);
}
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
url: contextPath + '/live/queryCameraRecord',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
window.self.$.messager.alert("获取摄像头列表失败", data.message, "error");
} else {
$("#cameraCode").myCombobox({
prompt: "选择摄像头",
width: 200,
data: data.data,
valueField: "cameraCode",
textField: "cameraName"
});
}
}
});
});
</script>
</body>
</html>
\ No newline at end of file
... ...