This commit is contained in:
cxh 2026-01-09 16:57:01 +08:00
parent d4d435f572
commit fd4b038e72

View File

@ -113,25 +113,25 @@ std::string RTMPManager::make_key(const std::string& name) { return name + "_mai
GstElement* RTMPManager::create_pipeline(const Camera& cam) GstElement* RTMPManager::create_pipeline(const Camera& cam)
{ {
const int fps = 30;
const int bitrate = cam.bitrate; 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 stream_name = cam.name;
const std::string rtmp_url = "rtmp://127.0.0.1:1935/" + stream_name; const std::string rtmp_url = "rtmp://127.0.0.1:1935/" + stream_name;
std::string pipeline_str = std::string pipeline_str =
// === V4L2 === // ===== V4L2 Source =====
"v4l2src device=" + cam.device + "v4l2src device=" + cam.device +
" io-mode=dmabuf do-timestamp=true " " io-mode=dmabuf do-timestamp=true "
// === 完全匹配驱动格式 === // ⚠️ 不再锁死 framerate这是装车最关键的一步
"! video/x-raw,format=NV12,width=1280,height=960,framerate=30/1 " "! 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 " "! mpph264enc name=enc "
"rc-mode=cbr " "rc-mode=cbr "
"bps=" + "bps=" +
@ -143,14 +143,16 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam)
"profile=main " "profile=main "
"header-mode=each-idr " "header-mode=each-idr "
// === H264 === // ===== H264 Parse =====
"! h264parse config-interval=1 " "! h264parse config-interval=1 "
"! video/x-h264,stream-format=avc,alignment=au " "! video/x-h264,stream-format=avc,alignment=au "
// === RTMP === // ===== RTMP =====
"! flvmux streamable=true " "! flvmux streamable=true "
"! rtmpsink location=\"" + "! rtmpsink location=\"" +
rtmp_url + "\" sync=false async=false"; rtmp_url +
"\" "
"sync=false async=false";
GError* error = nullptr; GError* error = nullptr;
GstElement* pipeline = gst_parse_launch(pipeline_str.c_str(), &error); GstElement* pipeline = gst_parse_launch(pipeline_str.c_str(), &error);