From 364ee4c81a546c9f1211852192733e9eec20a8b4 Mon Sep 17 00:00:00 2001 From: cxh Date: Wed, 26 Nov 2025 09:44:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E9=9F=B3=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rtmp_manager.cpp | 78 +++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index 74ac28c..cbfb499 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -77,35 +77,61 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam) const std::string record_rtmp = "rtmp://127.0.0.1:2935/" + app + "/" + stream_name + "?vhost=record"; // 双路推流管线:一份流编码后 tee 分支分别送往两个 flvmux+rtmpsink - std::string pipeline_str = - "v4l2src name=src device=" + cam.device + - " ! " - "video/x-raw,format=NV12,width=" + - std::to_string(width) + ",height=" + std::to_string(height) + ",framerate=" + std::to_string(fps) + - "/1 ! " - "mpph264enc bps=" + - std::to_string(bitrate) + " gop=" + std::to_string(fps) + - " rc-mode=cbr ! " - "h264parse ! tee name=t " + // std::string pipeline_str = + // "v4l2src name=src device=" + cam.device + + // " ! " + // "video/x-raw,format=NV12,width=" + + // std::to_string(width) + ",height=" + std::to_string(height) + ",framerate=" + std::to_string(fps) + + // "/1 ! " + // "mpph264enc bps=" + + // std::to_string(bitrate) + " gop=" + std::to_string(fps) + + // " rc-mode=cbr ! " + // "h264parse ! tee name=t " - // --- 分支1:低延时远控 SRS --- - "t. ! queue max-size-buffers=5 leaky=downstream ! " - "flvmux streamable=true name=mux_live " - "audiotestsrc wave=silence ! audioconvert ! audioresample ! voaacenc ! aacparse ! mux_live. " - "mux_live. ! rtmpsink location=\"" + - live_rtmp + - "\" sync=false async=false " + // // --- 分支1:低延时远控 SRS --- + // "t. ! queue max-size-buffers=5 leaky=downstream ! " + // "flvmux streamable=true name=mux_live " + // "audiotestsrc wave=silence ! audioconvert ! audioresample ! voaacenc ! aacparse ! mux_live. " + // "mux_live. ! rtmpsink location=\"" + + // live_rtmp + + // "\" sync=false async=false " - // --- 分支2:录像 SRS --- - "t. ! queue max-size-buffers=5 leaky=downstream ! " - "flvmux streamable=true name=mux_record " - "audiotestsrc wave=silence ! audioconvert ! audioresample ! voaacenc ! aacparse ! mux_record. " - "mux_record. ! rtmpsink location=\"" + - record_rtmp + - "\" sync=false async=false " + // // --- 分支2:录像 SRS --- + // "t. ! queue max-size-buffers=5 leaky=downstream ! " + // "flvmux streamable=true name=mux_record " + // "audiotestsrc wave=silence ! audioconvert ! audioresample ! voaacenc ! aacparse ! mux_record. " + // "mux_record. ! rtmpsink location=\"" + + // record_rtmp + + // "\" sync=false async=false " - // --- 可选第三分支:AI/检测 --- - "t. ! queue ! fakesink sync=false"; + // // --- 可选第三分支:AI/检测 --- + // "t. ! queue ! fakesink sync=false"; + + std::string pipeline_str = "v4l2src name=src device=" + cam.device + + " ! video/x-raw,format=NV12,width=" + std::to_string(width) + + ",height=" + std::to_string(height) + ",framerate=" + std::to_string(fps) + + "/1 " + " ! mpph264enc bps=" + + std::to_string(bitrate) + " gop=" + std::to_string(fps) + + " rc-mode=cbr " + " ! h264parse ! tee name=t " + + // ------ 分支1:live ------ + "t. ! queue max-size-buffers=5 leaky=downstream " + " ! flvmux streamable=true name=mux_live " + " ! rtmpsink location=\"" + + live_rtmp + + "\" sync=false async=false " + + // ------ 分支2:record ------ + "t. ! queue max-size-buffers=5 leaky=downstream " + " ! flvmux streamable=true name=mux_record " + " ! rtmpsink location=\"" + + record_rtmp + + "\" sync=false async=false " + + // ------ 分支3:AI ------ + "t. ! queue ! fakesink sync=false"; GError* error = nullptr; GstElement* pipeline = gst_parse_launch(pipeline_str.c_str(), &error);