This commit is contained in:
cxh 2026-01-09 10:51:34 +08:00
parent 5b0b6c1c65
commit 9c8c0768da

View File

@ -56,26 +56,19 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam)
std::string pipeline_str = "v4l2src device=" + cam.device + std::string pipeline_str = "v4l2src device=" + cam.device +
" io-mode=dmabuf " " io-mode=dmabuf "
"do-timestamp=true " // ⭐⭐ 正确位置:就在 v4l2src 上
// ⭐ 强制打时间戳(关键)
"! identity do-timestamp=true "
// 原始 4:3 输入
"! video/x-raw,format=NV12,width=1280,height=960,framerate=30/1 " "! video/x-raw,format=NV12,width=1280,height=960,framerate=30/1 "
// 裁成 16:9
"! videocrop top=120 bottom=120 " "! videocrop top=120 bottom=120 "
// 缩放到目标分辨率
"! videoscale " "! videoscale "
"! video/x-raw,width=" + "! video/x-raw,width=" +
std::to_string(cam.width) + ",height=" + std::to_string(cam.height) + std::to_string(cam.width) + ",height=" + std::to_string(cam.height) +
" " " "
// 缓冲(只在这里允许丢帧)
"! queue max-size-buffers=12 max-size-time=0 leaky=downstream " "! queue max-size-buffers=12 max-size-time=0 leaky=downstream "
// 编码
"! mpph264enc rc-mode=cbr " "! mpph264enc rc-mode=cbr "
"bps=" + "bps=" +
std::to_string(cam.bitrate) + std::to_string(cam.bitrate) +
@ -84,12 +77,11 @@ GstElement* RTMPManager::create_pipeline(const Camera& cam)
"header-mode=each-idr " "header-mode=each-idr "
"profile=main " "profile=main "
// 解析 + 帧探针位置
"! h264parse name=parse config-interval=1 " "! h264parse name=parse config-interval=1 "
"! video/x-h264,stream-format=avc,alignment=au " "! video/x-h264,stream-format=avc,alignment=au "
// RTMP
"! flvmux streamable=true " "! flvmux streamable=true "
"! rtmpsink location=\"" + "! rtmpsink location=\"" +
rtmp_url + rtmp_url +
"\" " "\" "