修改live流

This commit is contained in:
cxh 2026-01-20 14:14:50 +08:00
parent 0c8eac2622
commit 389de678f9

View File

@ -69,59 +69,46 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam)
const std::string stream = cam.name + "_main";
const std::string app = "camera";
// live → 外网
const std::string live_rtmp = "rtmp://36.153.162.171:19435/" + app + "/" + stream + "?vhost=live";
// record → 本地 SRS录像
const std::string record_rtmp = "rtmp://127.0.0.1:2935/" + app + "/" + stream + "?vhost=record";
std::string pipeline_str = "v4l2src name=src device=" + cam.device +
" io-mode=dmabuf "
"! video/x-raw,format=NV12,width=1920,height=1080,"
"framerate=" +
"! video/x-raw,format=NV12,width=1920,height=1080,framerate=" +
std::to_string(cam.fps) +
"/1 "
"! videoscale "
"! video/x-raw,width=" +
std::to_string(cam.width) + ",height=" + std::to_string(cam.height) +
" "
"! queue max-size-buffers=2 max-size-time=0 leaky=downstream "
"! mpph264enc rc-mode=cbr "
"bps=" +
std::to_string(cam.bitrate) +
" "
"gop=" +
std::to_string(cam.fps) +
" "
" ! queue max-size-buffers=2 leaky=downstream "
"! mpph264enc rc-mode=cbr bps=" +
std::to_string(cam.bitrate) + " gop=" + std::to_string(cam.fps) +
" header-mode=each-idr profile=baseline "
"! h264parse config-interval=1 "
"! tee name=t "
// ===== record永远开 =====
"t. ! queue max-size-buffers=5 leaky=downstream "
"! flvmux streamable=true "
"! rtmpsink location=\"" +
// ========= 录像(永远启用)============
"t. ! queue max-size-buffers=8 leaky=downstream "
"! flvmux name=rec_mux streamable=true "
"! rtmpsink name=rec_sink location=\"" +
record_rtmp +
"\" sync=false async=false "
"\" sync=false async=false drop-on-latency=true "
// ===== livevalve 控制 =====
"t. ! queue max-size-buffers=5 leaky=downstream "
// ========= livevalve 控制)===========
"t. ! queue max-size-buffers=8 leaky=downstream "
"! valve name=live_valve drop=true "
"! flvmux streamable=true "
"! rtmpsink location=\"" +
live_rtmp + "\" sync=false async=false";
"! queue max-size-buffers=8 leaky=downstream "
"! flvmux name=live_mux streamable=true "
"! rtmpsink name=live_sink location=\"" +
live_rtmp + "\" sync=false async=false drop-on-latency=true ";
GError* error = nullptr;
GstElement* pipeline = gst_parse_launch(pipeline_str.c_str(), &error);
if (error)
GError* err = nullptr;
GstElement* pipeline = gst_parse_launch(pipeline_str.c_str(), &err);
if (err)
{
LOG_ERROR("[RTMP] Pipeline creation failed: " + std::string(error->message));
g_error_free(error);
LOG_ERROR("[RTMP] Pipeline creation failed: " + std::string(err->message));
g_error_free(err);
return nullptr;
}