新增rtmp分支

This commit is contained in:
cxh 2025-11-12 18:10:16 +08:00
parent b125c8db42
commit af37638f87

View File

@ -72,30 +72,40 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam)
const std::string stream_name = cam.name + "_main"; const std::string stream_name = cam.name + "_main";
const std::string app = "camera"; const std::string app = "camera";
const std::string location = "rtmp://127.0.0.1:1935/" + app + "/" + stream_name + "?vhost=live"; // 两个不同的 SRS 实例live 用于远控record 用于录像
const std::string live_rtmp = "rtmp://127.0.0.1:1935/" + app + "/" + stream_name + "?vhost=live";
const std::string record_rtmp = "rtmp://127.0.0.1:2935/" + app + "/" + stream_name + "?vhost=record";
std::string pipeline_str = "v4l2src name=src device=" + cam.device + // 双路推流管线:一份流编码后 tee 分支分别送往两个 flvmux+rtmpsink
" ! " std::string pipeline_str =
"video/x-raw,format=NV12,width=" + "v4l2src name=src device=" + cam.device +
std::to_string(width) + ",height=" + std::to_string(height) + " ! "
",framerate=" + std::to_string(fps) + "video/x-raw,format=NV12,width=" +
"/1 ! " std::to_string(width) + ",height=" + std::to_string(height) + ",framerate=" + std::to_string(fps) +
"tee name=t " "/1 ! "
// 主分支:编码 + RTMP 推流 "mpph264enc bps=" +
"t. ! queue ! " std::to_string(bitrate) + " gop=" + std::to_string(fps) +
"mpph264enc bps=" + " rc-mode=cbr ! "
std::to_string(bitrate) + " gop=" + std::to_string(fps) + "h264parse ! tee name=t "
" ! "
"h264parse ! flvmux streamable=true name=mux " // --- 分支1低延时远控 SRS ---
// 静音音频轨道(避免 RTMP 播放器报错) "t. ! queue max-size-buffers=5 leaky=downstream ! "
"audiotestsrc wave=silence ! audioconvert ! audioresample ! " "flvmux streamable=true name=mux_live "
"voaacenc ! aacparse ! mux. " "audiotestsrc wave=silence ! audioconvert ! audioresample ! voaacenc ! aacparse ! mux_live. "
// 输出 RTMP "mux_live. ! rtmpsink location=\"" +
"mux. ! rtmpsink name=sink location=\"" + live_rtmp +
location + "\" sync=false async=false "
"\" sync=false "
// 第二分支:预留 (AI 分析/录制) // --- 分支2录像 SRS ---
"t. ! queue ! fakesink sync=false"; "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";
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);