diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index b271e31..7aec1d6 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -113,25 +113,25 @@ std::string RTMPManager::make_key(const std::string& name) { return name + "_mai GstElement* RTMPManager::create_pipeline(const Camera& cam) { - const int fps = 30; const int bitrate = cam.bitrate; - const int gop = fps; + const int gop = 30; // 固定 GOP,不强依赖实时 fps const std::string stream_name = cam.name; const std::string rtmp_url = "rtmp://127.0.0.1:1935/" + stream_name; std::string pipeline_str = - // === V4L2 === + // ===== V4L2 Source ===== "v4l2src device=" + cam.device + " io-mode=dmabuf do-timestamp=true " - // === 完全匹配驱动格式 === - "! video/x-raw,format=NV12,width=1280,height=960,framerate=30/1 " + // ⚠️ 不再锁死 framerate(这是装车最关键的一步) + "! video/x-raw,format=NV12,width=1280,height=960 " - // === 解耦缓冲 === - "! queue max-size-buffers=4 max-size-time=0 max-size-bytes=0 " + // ===== 启动/抖动缓冲(吃掉脏帧)===== + "! queue max-size-buffers=8 max-size-time=0 max-size-bytes=0 " + "leaky=downstream " - // === 硬件编码(命名!)=== + // ===== MPP H.264 Encoder ===== "! mpph264enc name=enc " "rc-mode=cbr " "bps=" + @@ -143,14 +143,16 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam) "profile=main " "header-mode=each-idr " - // === H264 === + // ===== H264 Parse ===== "! h264parse config-interval=1 " "! video/x-h264,stream-format=avc,alignment=au " - // === RTMP === + // ===== RTMP ===== "! flvmux streamable=true " "! rtmpsink location=\"" + - rtmp_url + "\" sync=false async=false"; + rtmp_url + + "\" " + "sync=false async=false"; GError* error = nullptr; GstElement* pipeline = gst_parse_launch(pipeline_str.c_str(), &error);