优化管线

This commit is contained in:
cxh 2025-11-12 17:47:56 +08:00
parent 0281aeafdd
commit 9dde95485e

View File

@ -1,4 +1,4 @@
// rtsp_manager.cpp
// rtmp_manager.cpp
#include "rtmp_manager.hpp"
#include <arpa/inet.h>
@ -74,24 +74,22 @@ GstElement *RTMPManager::create_pipeline(const Camera &cam)
const std::string app = "camera";
const std::string location = "rtmp://127.0.0.1:1935/" + app + "/" + stream_name + "?vhost=live";
// 给关键元素起名字src, vc, enc, par, mux, sink, tee
std::string pipeline_str = "v4l2src name=src device=" + cam.device +
" ! video/x-raw,width=" + std::to_string(width) + ",height=" + std::to_string(height) +
" ! "
"video/x-raw,format=NV12,width=" +
std::to_string(width) + ",height=" + std::to_string(height) +
",framerate=" + std::to_string(fps) +
"/1 "
"! videoconvert name=vc ! video/x-raw,format=NV12 "
"! tee name=t "
"t. ! queue "
"! mpph264enc name=enc bps=" +
"/1 ! "
"tee name=t "
"t. ! queue max-size-buffers=5 leaky=downstream ! "
"mpph264enc bps=" +
std::to_string(bitrate) + " gop=" + std::to_string(fps) +
" "
"! h264parse name=par "
"! flvmux name=mux streamable=true "
" rc-mode=cbr ! "
"h264parse ! flvmux streamable=true name=mux "
"audiotestsrc wave=silence ! audioconvert ! audioresample ! voaacenc ! aacparse ! mux. "
"mux. ! rtmpsink name=sink location=\"" +
"mux. ! rtmpsink location=\"" +
location +
"\" sync=false "
// 预留第二路 tee 分支(以后加叠加/探测都行),先丢掉
"\" sync=false async=false "
"t. ! queue ! fakesink sync=false";
GError* error = nullptr;