feat(video): 添加视频分析配置和RTSP服务器启动脚本

- 在application.yml中添加视频分析相关配置项,包括AI检测开关、RTSP连接参数
- 新增detection-config.json模型配置文件,支持YOLO目标检测模型
- 优化RTSP流媒体传输配置,添加TCP/UDP传输协议支持和超时重试机制
-修复模型配置文件路径问题,从/resources/models/调整为/libs/models/
- 更新JavaCV和OpenCV依赖版本,提升视频处理性能
- 添加Windows和Linux平台的RTSP测试服务器启动脚本
- 默认关闭AI检测功能,避免启动时出现错误- 增强RTSP连接稳定性,添加更多兼容性选项
This commit is contained in:
2025-09-27 18:52:40 +08:00
parent 68e8afd4ce
commit 3c3f2fe25b
9 changed files with 128 additions and 29 deletions

View File

@@ -181,7 +181,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
// 初始化模型管理器
if (modelManager == null) {
modelManager = new ModelManager();
URL json = getClass().getResource("/models/models.json");
URL json = getClass().getResource("/libs/models/models.json");
if (json != null) {
modelManager.load(json);
}

View File

@@ -69,7 +69,7 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable
/*** ====== 新增:推理相关字段 ====== ***/
// 开关:是否启用检测(可对外提供 setter
private boolean enableDetection = true;
private boolean enableDetection = false; // 默认关闭,避免启动错误
// 模型与推理
private ModelManager modelManager;
@@ -98,7 +98,12 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable
private void initDetectors() throws Exception {
if (!enableDetection) return;
modelManager = new ModelManager();
URL json = getClass().getResource("/models/models.json");
URL json = getClass().getResource("/libs/models/models.json");
if (json == null) {
log.warn("模型配置文件未找到,禁用检测功能");
enableDetection = false;
return;
}
modelManager.load(json);
// 单模型: detector = modelManager.get("person-helmet");
@@ -130,10 +135,14 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable
grabber.setOption("loglevel", "error"); // 稳定后压低日志
if (cameraDto.getUrl().toLowerCase().startsWith("rtsp://")) {
grabber.setOption("rtsp_transport", "tcp"); // 你要测 UDP 再改
// 尝试TCP传输如果失败则尝试UDP
grabber.setOption("rtsp_transport", "tcp");
grabber.setOption("allowed_media_types", "video");
grabber.setOption("max_delay", "500000");
grabber.setOption("user_agent", "Lavf/60");
// 添加更多RTSP选项以提高兼容性
grabber.setOption("rtsp_flags", "prefer_tcp");
grabber.setOption("timeout", "10000000"); // 10秒超时
} else if (cameraDto.getUrl().toLowerCase().startsWith("rtmp://")) {
grabber.setOption("rtmp_buffer", "1000");
} else if ("desktop".equalsIgnoreCase(cameraDto.getUrl())) {