|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.zhehekeji.web.lib.hik;
|
|
|
|
|
|
|
|
|
|
import com.sun.jna.ptr.IntByReference;
|
|
|
|
|
import com.zhehekeji.common.util.PathUtil;
|
|
|
|
|
import com.zhehekeji.core.util.Assert;
|
|
|
|
|
import com.zhehekeji.web.lib.CameraConnMap;
|
|
|
|
|
@ -7,8 +8,12 @@ import com.zhehekeji.web.lib.CameraControlModule;
|
|
|
|
|
import com.zhehekeji.web.lib.joyware.NetSDKLib;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Timer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 云台控制接口实现
|
|
|
|
|
@ -252,24 +257,109 @@ public class HikCameraControlModuleImpl implements CameraControlModule {
|
|
|
|
|
|
|
|
|
|
log.info("start download mp4 path:{} ",path);
|
|
|
|
|
int lUserID = CameraConnMap.getConnId(cameraId).intValue();
|
|
|
|
|
// HCNetSDK.NET_DVR_PLAYCOND net_dvr_playcond = new HCNetSDK.NET_DVR_PLAYCOND();
|
|
|
|
|
// net_dvr_playcond.struStartTime = startTime;
|
|
|
|
|
// net_dvr_playcond.struStopTime = startTime;
|
|
|
|
|
|
|
|
|
|
int result = HikLoginModuleImpl.hcNetsdk.NET_DVR_GetFileByTime_V40(lUserID,path.getBytes(StandardCharsets.UTF_8),struDownloadCond);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
log.error("downloadMp4 error:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId);
|
|
|
|
|
log.error("downloadMp4 error code:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId);
|
|
|
|
|
} else {
|
|
|
|
|
Integer process = 0;
|
|
|
|
|
//Boolean ok1 = HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(result, HikLoginModuleImpl.hcNetsdk.NET_DVR_SET_TRANS_TYPE,process,null);
|
|
|
|
|
Boolean ok = HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(result, HikLoginModuleImpl.hcNetsdk.NET_DVR_PLAYSTART,process,null);
|
|
|
|
|
|
|
|
|
|
Boolean ok = HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(result, HikLoginModuleImpl.hcNetsdk.NET_DVR_PLAYSTART,0,null);
|
|
|
|
|
if(!ok){
|
|
|
|
|
log.error("downloadMp4 error:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId);
|
|
|
|
|
log.error("downloadMp4 error code:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId);
|
|
|
|
|
}
|
|
|
|
|
Timer downloadtimer = new Timer();
|
|
|
|
|
downloadtimer.schedule(new DownloadTask(result,downloadtimer,path), 0, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DownloadTask extends java.util.TimerTask {
|
|
|
|
|
private Integer handler;
|
|
|
|
|
private Timer downloadtimer;
|
|
|
|
|
|
|
|
|
|
private String path;
|
|
|
|
|
public DownloadTask(Integer handler,Timer downloadtimer,String path){
|
|
|
|
|
this.handler = handler;
|
|
|
|
|
this.downloadtimer = downloadtimer;
|
|
|
|
|
this.path = path;
|
|
|
|
|
}
|
|
|
|
|
//定时器函数
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
IntByReference nPos = new IntByReference(0);
|
|
|
|
|
HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(handler, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos);
|
|
|
|
|
if (nPos.getValue() > 100)
|
|
|
|
|
{
|
|
|
|
|
HikLoginModuleImpl.hcNetsdk.NET_DVR_StopGetFile(handler);
|
|
|
|
|
downloadtimer.cancel();
|
|
|
|
|
log.error("download mp4 error");
|
|
|
|
|
}
|
|
|
|
|
if (nPos.getValue() == 100)
|
|
|
|
|
{
|
|
|
|
|
HikLoginModuleImpl.hcNetsdk.NET_DVR_StopGetFile(handler);
|
|
|
|
|
downloadtimer.cancel();
|
|
|
|
|
//ffmpeg转码
|
|
|
|
|
log.info("download over");
|
|
|
|
|
String ffmpegFile = path+"ffmpeg.mp4";
|
|
|
|
|
convetor(path,ffmpegFile);
|
|
|
|
|
PathUtil.deleteFile(path);
|
|
|
|
|
File file = new File(ffmpegFile);
|
|
|
|
|
file.renameTo(new File(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void convetor(String videoInputPath, String videoOutPath){
|
|
|
|
|
List<String> command = new ArrayList<String>();
|
|
|
|
|
command.add("E:\\ffmpeg-N-104583-ge5367b481b-win64-gpl\\bin\\ffmpeg.exe");
|
|
|
|
|
command.add("-i");
|
|
|
|
|
command.add(videoInputPath);
|
|
|
|
|
command.add("-c");
|
|
|
|
|
command.add("copy");
|
|
|
|
|
command.add("-an");
|
|
|
|
|
command.add(videoOutPath);
|
|
|
|
|
ProcessBuilder builder = new ProcessBuilder(command);
|
|
|
|
|
Process process = null;
|
|
|
|
|
try {
|
|
|
|
|
process = builder.start();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
// 使用这种方式会在瞬间大量消耗CPU和内存等系统资源,所以这里我们需要对流进行处理
|
|
|
|
|
InputStream errorStream = process.getErrorStream();
|
|
|
|
|
InputStreamReader inputStreamReader = new InputStreamReader(errorStream);
|
|
|
|
|
BufferedReader br = new BufferedReader(inputStreamReader);
|
|
|
|
|
String line = "";
|
|
|
|
|
try {
|
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
}finally {
|
|
|
|
|
try {
|
|
|
|
|
if (br != null) {
|
|
|
|
|
br.close();
|
|
|
|
|
}
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
|
}
|
|
|
|
|
if (errorStream != null) {
|
|
|
|
|
errorStream.close();
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置预置点
|
|
|
|
|
*
|
|
|
|
|
|