wenhongquan hace 1 día
padre
commit
b97f71bafe
Se han modificado 6 ficheros con 51 adiciones y 126 borrados
  1. 0 111
      DOCKER_PLATFORM_FIX.md
  2. 5 1
      Dockerfile
  3. 3 3
      config.json
  4. 11 3
      docker-start.sh
  5. 24 1
      main.cpp
  6. 8 7
      src/rtsp_client.cpp

+ 0 - 111
DOCKER_PLATFORM_FIX.md

@@ -1,111 +0,0 @@
-# Docker平台配置修复说明
-
-## 问题描述
-
-Docker语言服务器报告警告:
-```
-FROM --platform flag should not use a constant value (FROM --platform flag should not use constant value "linux/amd64")
-```
-
-## 问题原因
-
-1. **硬编码平台限制**:在Dockerfile中直接使用 `--platform=linux/amd64` 硬编码了平台架构
-2. **缺乏灵活性**:无法支持多架构构建
-3. **不符合最佳实践**:Docker推荐使用构建参数来动态指定平台
-
-## 修复方案
-
-### 1. Dockerfile修改
-
-**修改前:**
-```dockerfile
-FROM --platform=linux/amd64 ubuntu:22.04 AS builder
-...
-FROM --platform=linux/amd64 ubuntu:22.04
-```
-
-**修改后:**
-```dockerfile
-# 构建参数定义平台架构,默认为linux/amd64
-ARG BUILDPLATFORM=linux/amd64
-ARG TARGETPLATFORM=linux/amd64
-
-FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS builder
-...
-FROM --platform=$TARGETPLATFORM ubuntu:22.04
-```
-
-### 2. 构建脚本更新
-
-**docker-start.sh修改:**
-```bash
-# 修改前
-docker build --platform linux/amd64 -t jtjai_media:latest .
-
-# 修改后
-docker build --build-arg BUILDPLATFORM=linux/amd64 --build-arg TARGETPLATFORM=linux/amd64 -t jtjai_media:latest .
-```
-
-## 使用方式
-
-### 1. 默认AMD64构建
-```bash
-# 使用默认参数构建(AMD64)
-docker build -t jtjai_media:latest .
-
-# 或使用启动脚本
-./docker-start.sh
-```
-
-### 2. 指定平台构建
-```bash
-# 构建ARM64版本
-docker build --build-arg BUILDPLATFORM=linux/arm64 --build-arg TARGETPLATFORM=linux/arm64 -t jtjai_media:arm64 .
-
-# 多平台构建
-docker buildx build --platform linux/amd64,linux/arm64 -t jtjai_media:multi .
-```
-
-### 3. Docker Compose部署
-```bash
-# docker-compose.yml已配置platform: linux/amd64
-docker-compose up -d
-```
-
-## 优势
-
-1. **消除警告**:解决Docker语言服务器的平台常量警告
-2. **提高灵活性**:支持通过构建参数指定不同平台
-3. **保持兼容性**:默认仍为AMD64平台,确保现有部署不受影响
-4. **支持多架构**:为将来支持ARM等架构打下基础
-5. **符合最佳实践**:遵循Docker官方推荐的构建参数使用方式
-
-## 验证
-
-1. **构建测试**:
-   ```bash
-   docker build -t jtjai_media:test .
-   ```
-
-2. **运行测试**:
-   ```bash
-   docker run --rm -p 8080:8080 jtjai_media:test
-   ```
-
-3. **平台检查**:
-   ```bash
-   docker inspect jtjai_media:test | grep Architecture
-   ```
-
-## 注意事项
-
-1. 默认平台仍为 `linux/amd64`,确保与现有部署兼容
-2. 如需构建其他架构版本,需要相应的基础镜像支持
-3. 多架构构建需要使用 `docker buildx` 命令
-4. ARM架构构建可能需要额外的依赖库配置
-
-## 相关文件
-
-- `Dockerfile` - 主要修改文件
-- `docker-start.sh` - 启动脚本更新
-- `docker-compose.yml` - 已符合规范,无需修改

+ 5 - 1
Dockerfile

@@ -104,5 +104,9 @@ RUN mkdir -p /app/output
 # 暴露HTTP服务端口
 EXPOSE 8080
 
-# 设置启动命令
+# 设置健康检查
+HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
+  CMD curl -f http://localhost:8080/api || exit 1
+
+# 设置启动命令(使用绝对路径)
 CMD ["/app/jtjai_media", "/app/config.json"]

+ 3 - 3
config.json

@@ -4,9 +4,9 @@
     "max_concurrent_streams": 2,
     "output_directory": "./output",
     "report_filename": "rtsp_report.json",
-    "connection_timeout_seconds": 3,
-    "read_timeout_seconds": 5,
-    "poll_cycles": 3,
+    "connection_timeout_seconds": 10,
+    "read_timeout_seconds": 15,
+    "poll_cycles": -1,
     "cycle_interval_seconds": 30
   },
   "streams": [

+ 11 - 3
docker-start.sh

@@ -107,13 +107,21 @@ show_access_info() {
     echo "  🏠 主页: http://localhost:8080/"
     echo "  📊 API文档: http://localhost:8080/api"
     echo ""
+    print_info "系统特性:"
+    echo "  🔄 自动无限循环拉取RTSP流"
+    echo "  📁 按时间戳自动分类存储视频文件"
+    echo "  🌐 Web界面实时监控和管理"
+    echo "  ⚡ Docker容器化部署,即启即用"
+    echo ""
     print_info "管理命令:"
-    echo "  查看日志: docker logs -f jtjai_media"
-    echo "  停止服务: docker stop jtjai_media"
-    echo "  启动服务: docker start jtjai_media"
+    echo "  查看实时日志: docker logs -f jtjai_media"
+    echo "  停止所有服务: docker stop jtjai_media"
+    echo "  启服务: docker restart jtjai_media"
     echo "  删除容器: docker rm -f jtjai_media"
+    echo "  停止脚本: ./docker-stop.sh"
     echo ""
     print_info "输出目录: $(pwd)/output"
+    print_warn "注意:系统将持续运行,按Ctrl+C停止容器内程序但保持Web服务"
     print_info "=========================================="
 }
 

+ 24 - 1
main.cpp

@@ -132,6 +132,8 @@ int main(int argc, char* argv[]) {
             std::cout << "\n========== 轮询周期 " << current_cycle;
             if (global_config.poll_cycles != -1) {
                 std::cout << "/" << global_config.poll_cycles;
+            } else {
+                std::cout << " (无限循环)";
             }
             std::cout << " ==========" << std::endl;
             
@@ -240,7 +242,28 @@ int main(int argc, char* argv[]) {
             }
         }
         
-        std::cout << "\n程序执行完成" << std::endl;
+        if (global_config.poll_cycles != -1) {
+            std::cout << "\n所有轮询周期已完成" << std::endl;
+        } else {
+            std::cout << "\n接收到中断信号,退出轮询" << std::endl;
+        }
+        
+        // 保持HTTP服务器运行,即使轮询完成
+        if (g_http_server && !g_interrupted.load()) {
+            std::cout << "\n🌐 HTTP管理服务器继续运行..." << std::endl;
+            std::cout << "📱 您可以继续通过 http://localhost:8080/manager 管理文件" << std::endl;
+            std::cout << "▶️  按 Ctrl+C 停止服务器" << std::endl;
+            
+            // 等待中断信号
+            while (!g_interrupted.load()) {
+                std::this_thread::sleep_for(std::chrono::seconds(1));
+            }
+            
+            std::cout << "\n正在停止HTTP服务器..." << std::endl;
+            g_http_server->stop();
+        }
+        
+        std::cout << "\nHTTP服务器已停止" << std::endl;
         
     } catch (const std::exception& e) {
         std::cerr << "程序执行异常: " << e.what() << std::endl;

+ 8 - 7
src/rtsp_client.cpp

@@ -133,17 +133,18 @@ bool RTSPClient::initialize_input() {
     input_format_ctx_->interrupt_callback.callback = interrupt_callback;
     input_format_ctx_->interrupt_callback.opaque = this;
     
-    // 设置RTSP选项(优化快速失败检测
+    // 设置RTSP选项(Docker环境优化)
     AVDictionary* options = nullptr;
     av_dict_set(&options, "rtsp_transport", "tcp", 0);
-    av_dict_set(&options, "timeout", "3000000", 0);  // 3秒连接超时
-    av_dict_set(&options, "stimeout", "2000000", 0);  // 2秒读取超时
-    av_dict_set(&options, "max_delay", "500000", 0);  // 最大延迟500ms
+    av_dict_set(&options, "timeout", "10000000", 0);  // 10秒连接超时
+    av_dict_set(&options, "stimeout", "5000000", 0);  // 5秒读取超时
+    av_dict_set(&options, "max_delay", "1000000", 0);  // 最大延迟1秒
     av_dict_set(&options, "reorder_queue_size", "10", 0);  // 减小缓冲队列
+    av_dict_set(&options, "buffer_size", "65536", 0);  // 设置缓冲区大小
     
     // 设置超时时间(用于中断回调)
     start_time_us_ = av_gettime();
-    timeout_us_ = 3000000LL;  // 3秒超时
+    timeout_us_ = connection_timeout_ * 1000000LL;  // 使用配置的连接超时
     
     std::cout << "尝试连接RTSP流: " << config_.rtsp_url << std::endl;
     
@@ -167,9 +168,9 @@ bool RTSPClient::initialize_input() {
     
     std::cout << "成功连接RTSP流,获取流信息..." << std::endl;
     
-    // 获取流信息(使用较短超时)
+    // 获取流信息(使用配置的超时)
     start_time_us_ = av_gettime();
-    timeout_us_ = 2000000LL;  // 2秒超时
+    timeout_us_ = read_timeout_ * 1000000LL;  // 使用配置的读取超时
     
     ret = avformat_find_stream_info(input_format_ctx_, nullptr);
     if (ret < 0) {