Loading ruoyi-admin/src/main/java/com/ruoyi/icc/RtspToMP4.java 0 → 100644 +93 −0 Original line number Diff line number Diff line package com.ruoyi.icc; import org.springframework.stereotype.Component; 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 */ @Component public class RtspToMP4 { public 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 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; } } ruoyi-admin/src/main/resources/application-druid.yml +2 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,9 @@ spring: druid: # 主库数据源 master: url: jdbc:mysql://192.168.4.221:3307/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: mysql password: root # 从库数据源 slave: # 从数据源开关/默认关闭 Loading ruoyi-admin/src/main/resources/application.yml +18 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ spring: # redis 配置 redis: # 地址 host: 192.168.4.221 host: localhost # 端口,默认为6379 port: 6379 # 数据库索引 Loading Loading @@ -137,7 +137,7 @@ flink: # 端口,默认为8081 port: 8081 # jarId jarId: 0b26a8a0-a2cc-43ff-b809-1d5ed0551804_my-flink-project-0.1.jar jarId: 0b1a0852-931e-4933-b1f6-6b7d9c4f7f1b_my-flink-project-0.1.jar # flink启动类 entryClass: com.censoft.flink.StreamingJob # 启动参数 Loading @@ -150,3 +150,19 @@ airestapi: # 端口,默认为8081 port: 8081 #大华ICC视频配置 icc: sdk: # host host: 124.160.33.135:4077 # 客户端模式 clientId: CompanyName clientSecret: 42bec152-8f04-476a-9aec-e7d616ff3cb3 # 密码校验模式 pwdClientId: CompanyName pwdClientSecret: 42bec152-8f04-476a-9aec-e7d616ff3cb3 username: TEST password: Admin123 # 使用授权类型password grantType: password Loading
ruoyi-admin/src/main/java/com/ruoyi/icc/RtspToMP4.java 0 → 100644 +93 −0 Original line number Diff line number Diff line package com.ruoyi.icc; import org.springframework.stereotype.Component; 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 */ @Component public class RtspToMP4 { public 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 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; } }
ruoyi-admin/src/main/resources/application-druid.yml +2 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,9 @@ spring: druid: # 主库数据源 master: url: jdbc:mysql://192.168.4.221:3307/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: mysql password: root # 从库数据源 slave: # 从数据源开关/默认关闭 Loading
ruoyi-admin/src/main/resources/application.yml +18 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ spring: # redis 配置 redis: # 地址 host: 192.168.4.221 host: localhost # 端口,默认为6379 port: 6379 # 数据库索引 Loading Loading @@ -137,7 +137,7 @@ flink: # 端口,默认为8081 port: 8081 # jarId jarId: 0b26a8a0-a2cc-43ff-b809-1d5ed0551804_my-flink-project-0.1.jar jarId: 0b1a0852-931e-4933-b1f6-6b7d9c4f7f1b_my-flink-project-0.1.jar # flink启动类 entryClass: com.censoft.flink.StreamingJob # 启动参数 Loading @@ -150,3 +150,19 @@ airestapi: # 端口,默认为8081 port: 8081 #大华ICC视频配置 icc: sdk: # host host: 124.160.33.135:4077 # 客户端模式 clientId: CompanyName clientSecret: 42bec152-8f04-476a-9aec-e7d616ff3cb3 # 密码校验模式 pwdClientId: CompanyName pwdClientSecret: 42bec152-8f04-476a-9aec-e7d616ff3cb3 username: TEST password: Admin123 # 使用授权类型password grantType: password