From b98d67d59046d86eeb0bcfae0698d2b4656afe54 Mon Sep 17 00:00:00 2001 From: cxh Date: Tue, 6 Jan 2026 16:58:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=81=E5=89=AA=E7=94=BB=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rtmp_manager.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index 5858826..4ff4c74 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -113,12 +113,9 @@ std::string RTMPManager::make_key(const std::string& name) { return name + "_mai GstElement* RTMPManager::create_pipeline(const Camera& cam) { - const int out_width = cam.width; - const int out_height = cam.height; - - const int fps = 30; // ⭐ 强制 30 - const int bitrate = cam.bitrate; // 建议 3.5M~4.0M - const int gop = 15; // ⭐ 半秒 I 帧 + const int fps = 30; + const int bitrate = cam.bitrate; // 3.5M~4M + const int gop = 15; const std::string stream_name = cam.name; const std::string rtmp_url = "rtmp://127.0.0.1:1935/" + stream_name; @@ -126,18 +123,25 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam) std::string pipeline_str = "v4l2src name=src device=" + cam.device + " io-mode=dmabuf " + // 原始 4:3 输入 "! video/x-raw,format=NV12," "width=1280,height=960," "framerate=30/1 " + // ⭐ 裁成 16:9(上下各裁 120) + "! videocrop top=120 bottom=120 " + + // 可选:如果你想输出非 1280x720(比如 960x540) "! videoscale " "! video/x-raw," "width=" + - std::to_string(out_width) + ",height=" + std::to_string(out_height) + + std::to_string(cam.width) + ",height=" + std::to_string(cam.height) + " " + // 队列(建议后面再把 leaky 去掉) "! queue max-size-buffers=2 max-size-time=0 leaky=downstream " + // 编码 "! mpph264enc " "rc-mode=cbr " "bps=" + @@ -147,7 +151,7 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam) std::to_string(gop) + " " "header-mode=each-idr " - "profile=main " // ⭐ 关键改动 + "profile=main " "! h264parse config-interval=1 " "! video/x-h264,stream-format=avc,alignment=au "