|
@@ -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
|