This commit is contained in:
cxh 2026-01-09 11:32:56 +08:00
parent 45440a71dc
commit 8499411970

View File

@ -114,30 +114,34 @@ 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 fps = 30;
const int bitrate = cam.bitrate; const int bitrate = cam.bitrate; // 3.5M~4M
const int gop = 15; // ⭐ 从 4 改为 15非常重要 const int gop = 4;
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 = "v4l2src device=" + cam.device + std::string pipeline_str = "v4l2src name=src device=" + cam.device +
" io-mode=dmabuf " " io-mode=dmabuf "
// 原始 4:3 输入
"! video/x-raw,format=NV12," "! video/x-raw,format=NV12,"
"width=1280,height=960," "width=1280,height=960,"
"framerate=30/1 " "framerate=30/1 "
// ⭐ 裁成 16:9上下各裁 120
"! videocrop top=120 bottom=120 " "! videocrop top=120 bottom=120 "
// 可选:如果你想输出非 1280x720比如 960x540
"! videoscale " "! videoscale "
"! video/x-raw," "! video/x-raw,"
"width=" + "width=" +
std::to_string(cam.width) + ",height=" + std::to_string(cam.height) + std::to_string(cam.width) + ",height=" + std::to_string(cam.height) +
" " " "
// ⭐ 缓冲拉开,避免瞬时饿死 // 队列(建议后面再把 leaky 去掉)
"! queue max-size-buffers=8 max-size-time=0 leaky=downstream " "! queue max-size-buffers=2 max-size-time=0 leaky=downstream "
// 编码
"! mpph264enc " "! mpph264enc "
"rc-mode=cbr " "rc-mode=cbr "
"bps=" + "bps=" +
@ -151,7 +155,6 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam)
"! h264parse config-interval=1 " "! h264parse config-interval=1 "
"! video/x-h264,stream-format=avc,alignment=au " "! video/x-h264,stream-format=avc,alignment=au "
"! flvmux streamable=true " "! flvmux streamable=true "
"! rtmpsink location=\"" + "! rtmpsink location=\"" +