|
@@ -44,7 +44,7 @@ public class TestController {
|
|
|
returnResult.reason = "回放文件名称生成失败";
|
|
|
return returnResult;
|
|
|
}
|
|
|
- logger.info("回放文件地址:" + targetFile);
|
|
|
+ logger.info("playback path: " + targetFile);
|
|
|
|
|
|
File mp4File = new File(targetFile);
|
|
|
String targetFileName = mp4File.getName();
|
|
@@ -67,7 +67,7 @@ public class TestController {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- // 转码
|
|
|
+ logger.info("-------- start transcoding --------");
|
|
|
Map<String, String> data = new HashMap<String, String>(4);
|
|
|
convetorVideo(downloadFile, targetFile);
|
|
|
data.put("url", OtherTools.playMp4RootUrl + OtherTools.getMp4NamePrefix(targetFileName));
|
|
@@ -103,48 +103,50 @@ public class TestController {
|
|
|
|
|
|
// 准备文件下载
|
|
|
NativeLong loadHandle = hcNetSdk.NET_DVR_GetFileByTime(lUserID, new NativeLong(camera.channel), getHkTime(camera.startDateStr), getHkTime(camera.endDateStr), filePath);
|
|
|
- logger.info("hksdk(视频)-获取播放句柄信息,状态值:" + hcNetSdk.NET_DVR_GetLastError());
|
|
|
-
|
|
|
- if (loadHandle.intValue() >= 0) {
|
|
|
+ logger.info("hksdk playback file status: " + loadHandle.longValue());
|
|
|
+
|
|
|
+ if (loadHandle.longValue() >= 0) {
|
|
|
// 判断文件夹是否存在
|
|
|
File files = new File(filePath);
|
|
|
if(!files.exists()){
|
|
|
files.mkdirs();
|
|
|
}
|
|
|
|
|
|
+ // 发送回放开始的信号
|
|
|
hcNetSdk.NET_DVR_PlayBackControl(loadHandle, HCNetSDKWindows.NET_DVR_PLAYSTART, 0, null);
|
|
|
|
|
|
- int tmp = -1;
|
|
|
IntByReference pos = new IntByReference();
|
|
|
while (true) {
|
|
|
boolean backFlag = hcNetSdk.NET_DVR_PlayBackControl(loadHandle, HCNetSDKWindows.NET_DVR_PLAYGETPOS, 0, pos);
|
|
|
+ // 回放下载异常,直接跳出
|
|
|
if (!backFlag) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ logger.warn("hksdk download exception");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
int produce = pos.getValue();
|
|
|
- if ((produce % 10) == 0 && tmp != produce) {//输出进度
|
|
|
- tmp = produce;
|
|
|
- logger.info("hksdk(视频)-视频下载进度:" + "==" + produce + "%");
|
|
|
- }
|
|
|
+ if (produce > 0) {
|
|
|
+ logger.info("hksdk download progress: " + produce + "%");
|
|
|
+ }
|
|
|
+
|
|
|
if (produce == 100) {//下载成功
|
|
|
hcNetSdk.NET_DVR_StopGetFile(loadHandle);
|
|
|
- hcNetSdk.NET_DVR_Logout(lUserID);//退出录像机
|
|
|
- logger.info("hksdk(视频)-退出状态" + hcNetSdk.NET_DVR_GetLastError());
|
|
|
+ hcNetSdk.NET_DVR_Logout(lUserID);
|
|
|
+ logger.info("hksdk exit status: " + hcNetSdk.NET_DVR_GetLastError());
|
|
|
//hcNetSdk.NET_DVR_Cleanup(); // 这里不进行释放
|
|
|
return "true";
|
|
|
}
|
|
|
if (produce > 100) { //下载失败,异常终止,这时返回true
|
|
|
hcNetSdk.NET_DVR_StopGetFile(loadHandle);
|
|
|
- int net_DVR_GetLastError = hcNetSdk.NET_DVR_GetLastError();
|
|
|
- logger.warn("hksdk(视频)-海康sdk由于网络原因或DVR忙,下载异常终止! 错误原因:" + net_DVR_GetLastError);
|
|
|
- hcNetSdk.NET_DVR_Logout(lUserID);//退出录像机
|
|
|
+ logger.info("hksdk exit status: " + hcNetSdk.NET_DVR_GetLastError());
|
|
|
+ hcNetSdk.NET_DVR_Logout(lUserID);
|
|
|
return "true";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int net_DVR_GetLastError = hcNetSdk.NET_DVR_GetLastError();
|
|
|
- logger.error("hksdk(视频)-下载失败,失败码" + net_DVR_GetLastError);
|
|
|
+ logger.error("hksdk download failed: " + net_DVR_GetLastError);
|
|
|
return "文件下载失败,失败码:" + net_DVR_GetLastError;
|
|
|
}
|
|
|
|
|
@@ -249,8 +251,8 @@ public class TestController {
|
|
|
errorStream.close();
|
|
|
}
|
|
|
|
|
|
- File sourceFile = new File(videoInputFile);
|
|
|
- sourceFile.delete();
|
|
|
+ //File sourceFile = new File(videoInputFile);
|
|
|
+ //sourceFile.delete();
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|