Selaa lähdekoodia

完善海康云台控制接口,升级javacv1.5.6,优化打包内容减小体积

MisterZhang 4 vuotta sitten
vanhempi
commit
d3dcb68507

+ 20 - 1
README.md

@@ -5,7 +5,7 @@
 Springboot、netty实现的http-flv、websocket-flv流媒体服务(可用于直播点播),支持rtsp、h264、h265等、rtmp等多种源,h5纯js播放(不依赖flash),不需要依赖nginx等第三方,延迟大部分在1-5秒内(已经支持转复用,h264的流自动转封装,超低延迟。PS:当然还有种更低延迟的不用flv方案没时间写了,但是主要是flv比较大众,这个一般也够用了)。
 
 
-[成品下载-7.16](https://pan.baidu.com/s/1kx3pwYVG_HfAt8JmQti86g "成品下载")
+[成品下载-7.16,此版本已不是最新,新版本请自行下载编译](https://pan.baidu.com/s/1kx3pwYVG_HfAt8JmQti86g "成品下载-7.16,此版本已不是最新,新版本请自行下载编译")
 
 
 链接:https://pan.baidu.com/s/1kx3pwYVG_HfAt8JmQti86g 
@@ -27,6 +27,7 @@ PS:项目里已经集成最新版编译好的前端,由于前端只是个dem
 - 支持hls内存切片(不占用本地磁盘,只占用网络资源)
 - 重连功能
 - 支持javacv、ffmpeg方式切换
+- 云台控制(目前只支持海康、大华待更新)
 
 #### 软件架构
 - netty负责播放地址解析及视频传输,通过javacv推拉流存到内存里,直接通过输出到前端播放
@@ -83,6 +84,17 @@ ffmpeg=true 使用ffmpeg方式,提高兼容稳定性(不支持的流可以
 //hls=true(目前还不支持此参数,只能api或者网页端控制开启)
 ```
 
+- 云台功能
+```
+目前支持海康相机,大华待更新
+http://localhost:8888/hk/ctrl?ip=192.168.2.120&op=left&username=admin&password=VZCDOY
+ip 相机ip
+op 操作,up、down、left、right、left_up、left_down、right_up、right_down、big、small
+username 相机用户名
+password 相机密码
+port 控制端口(可不传)
+```
+
 - 页面功能
 ```
 可以访问 http://localhost:8888
@@ -126,6 +138,13 @@ java -jar -Dserver.port=页面端口 -Dmediaserver.port=媒体端口 EasyMedia-x
 2.  标准的maven项目,sts、eclipse或者idea导入,直接运行main方法
 
 
+#### 更新说明 2021-09-17
+- 升级javacv1.5.6
+- 完善海康云台控制接口
+- 修复ffmpeg rtmp播放不了问题
+- 优化打包,移除不需要的平台(mac等),目前支持window、linux,包大小到100m内
+
+
 #### 更新说明 2021-07-16
 - 升级javacv1.5.5,解决花屏问题,提升启动运行速度
 - 移除camera.json,采用h2数据库,运行jar同级目录会生成emdata文件夹

+ 20 - 7
pom.xml

@@ -47,21 +47,34 @@
 			</exclusions>
 		</dependency>
 
-		<!-- 全量引入 ,包含ffmpeg、opencv等 -->
+		<!-- 全量引入 ,包含javacv、ffmpeg、opencv等 -->
 		<!-- <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv-platform</artifactId> 
-			<version>1.5.5</version> </dependency> -->
+			<version>1.5.6</version> </dependency> -->
 
-		<!-- 媒体只用到以下两个 -->
+		<!-- 媒体只用到以下两个,javacv、ffmpeg -->
 		<dependency>
 			<groupId>org.bytedeco</groupId>
 			<artifactId>javacv</artifactId>
-			<version>1.5.5</version>
+			<version>1.5.6</version>
 		</dependency>
-
-		<dependency>
+		
+		<!-- ffmpeg全平台引入 -->
+		<!-- <dependency>
 			<groupId>org.bytedeco</groupId>
 			<artifactId>ffmpeg-platform</artifactId>
-			<version>4.3.2-1.5.5</version>
+			<version>4.4-1.5.6</version>
+		</dependency> -->
+		<dependency>
+			<groupId>org.bytedeco</groupId>
+			<artifactId>ffmpeg</artifactId>
+			<version>4.4-1.5.6</version>
+			<classifier>windows-x86_64</classifier>
+		</dependency>
+		<dependency>
+			<groupId>org.bytedeco</groupId>
+			<artifactId>ffmpeg</artifactId>
+			<version>4.4-1.5.6</version>
+			<classifier>linux-x86_64</classifier>
 		</dependency>
 
 		<!-- 工具包 -->

+ 2 - 0
src/main/java/com/zj/EasyMediaApplication.java

@@ -2,12 +2,14 @@ package com.zj;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
 
 @SpringBootApplication
+@ServletComponentScan
 public class EasyMediaApplication {
 	
 	private static String jsonPath = "";

+ 33 - 12
src/main/java/com/zj/controller/CloudCtrlController.java

@@ -1,11 +1,17 @@
 package com.zj.controller;
 
+import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpSession;
+
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import com.zj.ctrl.CameraCtrl;
 import com.zj.ctrl.CloudCode;
 import com.zj.ctrl.Control;
 import com.zj.ctrl.LoginPlay;
+import com.zj.ctrl.MyNativeLong;
+import com.zj.ctrl.TempData;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.StrUtil;
@@ -15,21 +21,21 @@ import cn.hutool.core.util.StrUtil;
  * @author ZJ
  *
  */
+@RequestMapping("hk")
+@RestController
 public class CloudCtrlController {
 	
+//	http://localhost:8888/hk/ctrl?ip=192.168.2.120&op=left&username=admin&password=VZCDOY
+	
 	/**
-	 * @throws Exception 
-	 * 
+	 * 云台控制接口
+	 * @param session
+	 * @param camera
 	 */
 	@RequestMapping("ctrl")
-	public void name() throws Exception {
-
-		LoginPlay lp = new LoginPlay();
-		// 输入摄像机ip,端口,账户,密码登录
-		lp.doLogin("192.168.2.120", Convert.toShort("8000", (short) 8000), "admin",
-				"admin123");
-		
-		CameraCtrl camera = new CameraCtrl();
+	public void cloudCtrl(HttpSession session, CameraCtrl camera) {
+		checkLogin(camera);
+		session.setAttribute("ip", camera.getIp());
 
 		// 截取摄像机实时图片
 //		boolean imgSavePath = Control.getImgSavePath(camera.getIp(), "D:\\tempFile\\3.jpg");
@@ -136,7 +142,22 @@ public class CloudCtrlController {
 			Control.cloudControl(camera.getIp(), CloudCode.ZOOM_OUT, CloudCode.SPEED_LV6, CloudCode.END);
 		}
 
-
-
+	}
+	
+	/**
+	 * sdk登入
+	 */
+	private void checkLogin(CameraCtrl camera) {
+		MyNativeLong nativeLong = TempData.getTempData().getNativeLong(camera.getIp());
+		if(null == nativeLong) {
+			LoginPlay lp = new LoginPlay();
+			// 输入摄像机ip,端口,账户,密码登录
+			try {
+				boolean doLogin = lp.doLogin(camera.getIp(), Convert.toShort(camera.getPort(), (short) 8000), camera.getUsername(),
+						camera.getPassword());
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
 	}
 }

+ 3 - 1
src/main/java/com/zj/ctrl/CameraCtrl.java

@@ -8,6 +8,8 @@ import lombok.Setter;
 public class CameraCtrl {
 
 	private String ip;
-	private int port;
+	private int port = 8000;	//海康默认端口
+	private String username;
+	private String password;
 	private String op;
 }

+ 44 - 0
src/main/java/com/zj/ctrl/CtrlSessionListener.java

@@ -0,0 +1,44 @@
+package com.zj.ctrl;
+
+import javax.servlet.annotation.WebListener;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import cn.hutool.core.convert.Convert;
+
+/**
+ * session监听,用于自动断开云台控制会话
+ * @author ZJ
+ *
+ */
+@WebListener
+public class CtrlSessionListener implements HttpSessionListener {
+
+	@Override
+	public void sessionCreated(HttpSessionEvent event) {
+		HttpSessionListener.super.sessionCreated(event);
+		HttpSession session = event.getSession();
+		
+	}
+
+	@Override
+	public void sessionDestroyed(HttpSessionEvent event) {
+		// TODO Auto-generated method stub
+		HttpSessionListener.super.sessionDestroyed(event);
+		
+		HttpSession session = event.getSession();
+		
+		String ip = Convert.toStr(session.getAttribute("ip"));
+		if(ip != null) {
+			MyNativeLong nativeLong = TempData.getTempData().getNativeLong(ip);
+			boolean net_DVR_Logout = LoginPlay.hCNetSDK.NET_DVR_Logout(nativeLong.getlUserID());
+			if (net_DVR_Logout) {
+				//退出登入成功
+				TempData.getTempData().removeNativeLong(ip);
+			}
+		}
+		
+	}
+	
+}

+ 8 - 0
src/main/java/com/zj/ctrl/TempData.java

@@ -58,4 +58,12 @@ public class TempData {
 		nativeLongMap.put(IPKey, myNativeLong);
 	}
 	
+	/**
+	 * 移除
+	 * @param IPKey
+	 */
+	public void removeNativeLong(String IPKey) {
+		nativeLongMap.remove(IPKey);
+	}
+	
 }

+ 1 - 0
src/main/java/com/zj/ctrl/readme

@@ -0,0 +1 @@
+此目录主要是海康sdk专用,比如云台控制等,假如不需要,可以删除sdk和此目录,和流媒体服务互不相关