wenhongquan 1 day ago
parent
commit
8cc8a2853f
3 changed files with 88 additions and 63 deletions
  1. 34 50
      Dockerfile
  2. 37 0
      Dockerfile.simple
  3. 17 13
      src/rtsp_client.cpp

+ 34 - 50
Dockerfile

@@ -1,7 +1,7 @@
 # 多阶段构建Dockerfile for AMD64平台
 # RTSP视频流并发拉取系统
 
-# 构建参数定义平台架构,默认为linux/amd64
+# 构建参数定义平台架构,强制使用AMD64
 ARG BUILDPLATFORM=linux/amd64
 ARG TARGETPLATFORM=linux/amd64
 
@@ -15,36 +15,36 @@ ENV DEBIAN_FRONTEND=noninteractive
 ENV TZ=Asia/Shanghai
 
 # 更换为清华大学镜像源
-RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list && \
-    sed -i 's@//.*security.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list && apt-get update
+# RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list && \
+#     sed -i 's@//.*security.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
 
 # 安装构建依赖
-RUN apt-get update && apt-get install -y \
-    build-essential \
-    cmake \
-    git \
-    wget \
-    pkg-config \
-    libavcodec-dev \
-    libavformat-dev \
-    libavutil-dev \
-    libswscale-dev \
-    libfmt-dev \
-    libboost-all-dev \
-    && apt-get clean \
-    && rm -rf /var/lib/apt/lists/*
+# RUN apt-get update && apt-get install -y \
+#     build-essential \
+#     cmake \
+#     git \
+#     wget \
+#     pkg-config \
+#     libavcodec-dev \
+#     libavformat-dev \
+#     libavutil-dev \
+#     libswscale-dev \
+#     libfmt-dev \
+#     libboost-all-dev \
+#     && apt-get clean \
+#     && rm -rf /var/lib/apt/lists/*
 
 # 使用SourceForge镜像下载Boost 1.82(更稳定的下载源)
-RUN cd /tmp && \
-    wget -q --show-progress http://thfile.xt.wenhq.top:8083/boost_1_82_0.tar.bz2 -O boost_1_82_0.tar.bz2 && \
-    file boost_1_82_0.tar.bz2 && \
-    tar -xjf boost_1_82_0.tar.bz2 && \
-    cd boost_1_82_0 && \
-    ./bootstrap.sh --with-libraries=system,json && \
-    ./b2 -j$(nproc) variant=release link=shared threading=multi install && \
-    ldconfig && \
-    cd / && \
-    rm -rf /tmp/boost_1_82_0*
+# RUN cd /tmp && \
+#     wget -q --show-progress https://sourceforge.net/projects/boost/files/boost/1.82.0/boost_1_82_0.tar.bz2/download -O boost_1_82_0.tar.bz2 && \
+#     file boost_1_82_0.tar.bz2 && \
+#     tar -xjf boost_1_82_0.tar.bz2 && \
+#     cd boost_1_82_0 && \
+#     ./bootstrap.sh --with-libraries=system,json && \
+#     ./b2 -j$(nproc) variant=release link=shared threading=multi install && \
+#     ldconfig && \
+#     cd / && \
+#     rm -rf /tmp/boost_1_82_0*
 
 # 创建工作目录
 WORKDIR /app
@@ -65,35 +65,19 @@ RUN mkdir -p build && \
     make -j$(nproc)
 
 # ============================================
-# 阶段2: 运行环境 - 使用国内镜像加速
+# 阶段2: 运行环境 - 使用已配置好的基础镜像
 # ============================================
-FROM ubuntu:22.04
+FROM --platform=$TARGETPLATFORM k8s.device.wenhq.top:8583/docker_r/ubuntu:22.04
 
 # 设置环境变量
 ENV DEBIAN_FRONTEND=noninteractive
 ENV TZ=Asia/Shanghai
 
-# 更换为清华大学镜像源
-RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list && \
-    sed -i 's@//.*security.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
-
-# 安装运行时依赖
-RUN apt-get update && apt-get install -y \
-    libavcodec-dev \
-    libavformat-dev \
-    libavutil-dev \
-    libswscale-dev \
-    libfmt-dev \
-    libboost-system-dev \
-    curl \
-    && apt-get clean \
-    && rm -rf /var/lib/apt/lists/*
-
-# 从构建阶段复制Boost库
-COPY --from=builder /usr/local/lib/libboost* /usr/local/lib/
-COPY --from=builder /usr/local/include/boost /usr/local/include/boost
-# 更新库链接缓存
-RUN ldconfig
+# 如果需要额外安装调试工具,可以在这里添加
+# RUN apt-get update && apt-get install -y \
+#     curl \
+#     && apt-get clean \
+#     && rm -rf /var/lib/apt/lists/*
 
 # 创建应用目录
 WORKDIR /app

+ 37 - 0
Dockerfile.simple

@@ -0,0 +1,37 @@
+# 简化单阶段构建Dockerfile用于快速测试
+FROM k8s.device.wenhq.top:8583/docker_r/ubuntu:22.04
+
+# 设置环境变量
+ENV DEBIAN_FRONTEND=noninteractive
+ENV TZ=Asia/Shanghai
+
+# 创建工作目录
+WORKDIR /app
+
+# 复制项目文件
+COPY CMakeLists.txt ./
+COPY include/ ./include/
+COPY src/ ./src/
+COPY main.cpp ./
+COPY http_server_main.cpp ./
+COPY config.json ./
+COPY video_manager.html ./
+COPY rtsp-debug.sh ./
+
+# 设置脚本权限
+RUN chmod +x ./rtsp-debug.sh
+
+# 创建构建目录并编译
+RUN mkdir -p build && \
+    cd build && \
+    cmake .. && \
+    make -j$(nproc)
+
+# 创建输出目录
+RUN mkdir -p /app/output
+
+# 暴露HTTP服务端口
+EXPOSE 8080
+
+# 设置启动命令(使用绝对路径)
+CMD ["/app/build/jtjai_media", "/app/config.json"]

+ 17 - 13
src/rtsp_client.cpp

@@ -154,35 +154,39 @@ bool RTSPClient::initialize_input() {
     
     // 设置RTSP选项(Docker环境优化)
     AVDictionary* options = nullptr;
+    
+    // 基本RTSP客户端设置 - 明确指定客户端模式
     av_dict_set(&options, "rtsp_transport", "tcp", 0);  // 强制使用TCP传输
+    av_dict_set(&options, "rtsp_flags", "prefer_tcp", 0);  // 优先TCP,避免UDP问题
     
     // 根据是否为Docker环境调整超时和网络设置
     if (debug_mode) {
-        // Docker环境专用设置
-        av_dict_set(&options, "timeout", "15000000", 0);  // 15秒连接超时
-        av_dict_set(&options, "stimeout", "20000000", 0);  // 20秒Socket超时
-        av_dict_set(&options, "rw_timeout", "10000000", 0);  // 10秒读写超时
-        av_dict_set(&options, "listen_timeout", "5000000", 0);  // 5秒监听超时
+        // Docker环境专用设置 - 避免服务器模式
+        av_dict_set(&options, "stimeout", "15000000", 0);  // Socket超时15秒
+        av_dict_set(&options, "rw_timeout", "10000000", 0);  // 读写超时10秒
+        
+        // 明确禁用服务器/监听相关选项
+        av_dict_set(&options, "listen", "0", 0);  // 明确禁用监听模式
+        av_dict_set(&options, "listen_timeout", "0", 0);  // 禁用监听超时
         
         // 网络优化参数
-        av_dict_set(&options, "rtsp_flags", "listen", 0);  // 启用监听模式
         av_dict_set(&options, "fflags", "+discardcorrupt", 0);  // 丢弃损坏的包
         av_dict_set(&options, "flags", "+low_delay", 0);  // 低延迟模式
         av_dict_set(&options, "buffer_size", "1048576", 0);  // 1MB缓冲区
         av_dict_set(&options, "max_delay", "500000", 0);  // 最大延迟500ms
         
-        // 设置兼容的User-Agent
-        av_dict_set(&options, "user_agent", "LibVLC/3.0.0 (compatible; RTSP-Client)", 0);
+        // 设置兼容的User-Agent
+        av_dict_set(&options, "user_agent", "FFmpeg RTSP Client Docker", 0);
         
-        std::cout << "Docker环境超时配置: 连接15s, Socket20s, 读写10s" << std::endl;
+        std::cout << "Docker环境RTSP配置: TCP传输, Socket15s, 读写10s, 客户端模式" << std::endl;
     } else {
         // 本地环境设置
-        av_dict_set(&options, "timeout", "10000000", 0);  // 10秒连接超时
-        av_dict_set(&options, "stimeout", "8000000", 0);   // 8秒Socket超时
-        av_dict_set(&options, "user_agent", "RTSP-Client", 0);
+        av_dict_set(&options, "stimeout", "10000000", 0);  // Socket超时10秒
+        av_dict_set(&options, "rw_timeout", "8000000", 0);   // 读写超时8秒
+        av_dict_set(&options, "user_agent", "FFmpeg RTSP Client", 0);
     }
     
-    // 通用网络优化设置
+    // 通用RTSP客户端优化设置
     av_dict_set(&options, "reorder_queue_size", "10", 0);  // 减小重排序队列
     av_dict_set(&options, "analyzeduration", "2000000", 0);  // 分析时长2秒
     av_dict_set(&options, "probesize", "1048576", 0);  // 探测大小1MB