Commit 5ac4fedd authored by 周昊's avatar 周昊

1、开发保存录像地址

parent f25e0c24
...@@ -153,6 +153,25 @@ under the License. ...@@ -153,6 +153,25 @@ under the License.
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version> <version>8.0.28</version>
</dependency> </dependency>
<!-- ICC鉴权 -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-oauth</artifactId>
<version>1.0.9.1</version>
<exclusions>
<exclusion>
<artifactId>java-sdk-core</artifactId>
<groupId>com.dahuatech.icc</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-core</artifactId>
<version>1.0.9.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -8,6 +8,14 @@ import com.censoft.flink.transform.AlgorithmBaseFilterFunction; ...@@ -8,6 +8,14 @@ import com.censoft.flink.transform.AlgorithmBaseFilterFunction;
import com.censoft.flink.transform.AlgorithmTypeFlatMapFunction; import com.censoft.flink.transform.AlgorithmTypeFlatMapFunction;
import com.censoft.flink.transform.ResultExistFilterFunction; import com.censoft.flink.transform.ResultExistFilterFunction;
import com.censoft.flink.transform.UpdateLiveFilterFunction; import com.censoft.flink.transform.UpdateLiveFilterFunction;
import com.censoft.flink.utils.RtspToMP4;
import com.dahuatech.hutool.json.JSONObject;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import org.apache.flink.api.common.serialization.SimpleStringSchema; import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.api.java.utils.ParameterTool; import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.core.fs.FileSystem; import org.apache.flink.core.fs.FileSystem;
...@@ -16,11 +24,10 @@ import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator; ...@@ -16,11 +24,10 @@ import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer; import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer;
import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.List;
import java.util.Optional;
public class StreamingJob { public class StreamingJob {
...@@ -92,7 +99,10 @@ public class StreamingJob { ...@@ -92,7 +99,10 @@ public class StreamingJob {
warnPushBase.setGradeType(getAlgorithmPoById(algorithmPoList,Long.valueOf(algorithmPushDto.getAlgorithmName())) warnPushBase.setGradeType(getAlgorithmPoById(algorithmPoList,Long.valueOf(algorithmPushDto.getAlgorithmName()))
.getAlgorithmName()); .getAlgorithmName());
warnPushBase.setAlarmTime(new Date(algorithmPushDto.getTimeStamp() * 1000)); warnPushBase.setAlarmTime(new Date(algorithmPushDto.getTimeStamp() * 1000));
//获取图片地址
warnPushBase.setPicture("http://172.16.21.3"+algorithmPushDto.getPictureAddress()); warnPushBase.setPicture("http://172.16.21.3"+algorithmPushDto.getPictureAddress());
//获取视频地址
warnPushBase.setVideo(getVideo("1000790$1$0$0",1698868554L,1698868654L));
warnPushBase.setStatus("wait"); warnPushBase.setStatus("wait");
warnPushBase.setSendUserIds("|1|"); warnPushBase.setSendUserIds("|1|");
warnPushBase.setDelFlag(0); warnPushBase.setDelFlag(0);
...@@ -123,4 +133,46 @@ public class StreamingJob { ...@@ -123,4 +133,46 @@ public class StreamingJob {
.stream() .stream()
.filter(algorithmPo -> id.equals(algorithmPo.getId())).findFirst().get(); .filter(algorithmPo -> id.equals(algorithmPo.getId())).findFirst().get();
} }
private static String getVideo(String channelId, Long startTime, Long endTime) {
try {
//获取录像视频流
String rtsp = rtsp(channelId, startTime, endTime);
//视频流转mp4
String filePath = "D:\\data\\MP4\\1.mp4";
RtspToMP4.StartRecord("E:\\ffmpeg\\bin\\ffmpeg.exe",rtsp,filePath);
return filePath;
} catch (ClientException e) {
e.printStackTrace();
}
return "";
}
private static String rtsp(String channelId, Long startTime, Long endTime) throws ClientException {
IClient iClient = new DefaultClient();
GeneralRequest generalRequest =
new GeneralRequest("/evo-apigw/admin/API/SS/Playback/StartPlaybackByFile", com.dahuatech.hutool.http.Method.POST);
String body =
"{\n" +
" \"data\": {\n" +
" \"channelId\": \"" + channelId + "\",\n" +
" \"recordSource\": \"3\",\n" +
" \"startTime\": \"" + startTime + "\",\n" +
" \"endTime\": \"" + endTime + "\",\n" +
" \"streamType\": \"1\",\n" +
" \"recordType\": \"1\"\n" +
" }\n" +
"}";
generalRequest.body(body);
GeneralResponse response = iClient.doAction(generalRequest, generalRequest.getResponseClass());
String result = response.getResult();
JSONObject obj = JSONUtil.parseObj(response.getResult());
String url = obj.getJSONObject("data").getStr("url");
String token = obj.getJSONObject("data").getStr("token");
String[] parts = url.split("\\|");
return parts[0] + "?token=" + token+"&trackID=0";
}
} }
...@@ -28,6 +28,9 @@ public class AlgorithmWarnPushDto { ...@@ -28,6 +28,9 @@ public class AlgorithmWarnPushDto {
/** 图片地址 */ /** 图片地址 */
private String picture; private String picture;
/** 视频地址 */
private String video;
/** 处置状态 */ /** 处置状态 */
private String status; private String status;
......
package com.censoft.flink.utils;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* TODO:
*
* @Author: ZHANG
* @create: 2021/8/27 16:11
*/
public class RtspToMP4 {
public static class In implements Runnable{
private InputStream inputStream;
public In(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public void run() {
try {
//转成字符输入流
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "gbk");
int len = -1;
char[] c = new char[1024];
//读取进程输入流中的内容
while ((len = inputStreamReader.read(c)) != -1) {
String s = new String(c, 0, len);
System.out.print(s);
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
StartRecord("E:\\ffmpeg\\bin\\ffmpeg.exe","rtsp://192.168.18.203:554/av0_0","D:\\data\\MP4\\3.mp4");
}
public static Process StartRecord(String ffmpegPath, String streamUrl, String FilePath){
ProcessBuilder processBuilder = new ProcessBuilder();
//定义命令内容
List<String> command = new ArrayList<>();
command.add(ffmpegPath);
command.add("-rtsp_transport");
command.add("tcp");
command.add("-y");
command.add("-i");
command.add(streamUrl);
command.add("-c");
command.add("copy");
command.add("-f");
command.add("mp4");
command.add(FilePath);
processBuilder.command(command);
System.out.println("脚本:" + command.toString());
//将标准输入流和错误输入流合并,通过标准输入流读取信息
processBuilder.redirectErrorStream(true);
try {
//启动进程
Process process = processBuilder.start();
System.out.println("开始时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())));
//获取输入流
InputStream inputStream = process.getInputStream();
Thread inThread = new Thread(new In(inputStream));
inThread.start();
return process;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean stopRecord(Process process) {
try {
OutputStream os = process.getOutputStream();
os.write("q".getBytes());
// 一定要刷新
os.flush();
os.close();
} catch (Exception err) {
err.printStackTrace();
return false;
}
return true;
}
}
#服务地址 端口默认是443
#icc.sdk.host=115.236.17.59:9021
icc.sdk.host=172.16.51.2
#是否启用https访问,默认:是
#icc.sdk.enable.https=false
#认证类型=[client_credentials],[password],client_credentials:客户端鉴权模式;password:用户密码鉴权模式
icc.sdk.grantType=password
#-----------客户端鉴权模式--------------
#客户端鉴权模式申请访问凭证id
icc.sdk.clientId=CompanyName
#客户端鉴权模式申请访问凭证密钥
icc.sdk.clientSecret=67987667-8651-44f1-a3da-f6796e5f23e6
#客户端鉴权模式默认用户,默认是1,超级管理员
#icc.sdk.config.client.userId=1
#-----------用户密码鉴权模式--------------
#用户密码鉴权模式申请访问凭证id
icc.sdk.pwdClientId=CompanyName
#用户密码鉴权模式申请访问凭证密钥
icc.sdk.pwdClientSecret=67987667-8651-44f1-a3da-f6796e5f23e6
#用户名
icc.sdk.username=system
#密码
icc.sdk.password=Admin@123
#http调试模式 false:开启,true:关闭
icc.sdk.enable.https=true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment