This commit is contained in:
cxh 2025-09-16 18:19:42 +08:00
parent 9d39aa14d3
commit 2a49aef598
2 changed files with 21 additions and 6 deletions

View File

@ -63,6 +63,7 @@
"typeindex": "cpp", "typeindex": "cpp",
"typeinfo": "cpp", "typeinfo": "cpp",
"valarray": "cpp", "valarray": "cpp",
"variant": "cpp" "variant": "cpp",
"set": "cpp"
} }
} }

View File

@ -25,17 +25,31 @@ void RTSPManager::init()
// 创建 media factory // 创建 media factory
GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam) GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam)
{ {
int out_width = cam.width;
int out_height = cam.height;
// 如果是 1280x960则裁剪到 1280x720
std::string videocrop_str;
if (cam.width == 1280 && cam.height == 960)
{
out_height = 720;
// 使用 videocrop 元素从顶部裁剪 120 像素,总共裁剪 960->720
int crop_top = (960 - 720) / 2;
videocrop_str = " ! videocrop top=" + std::to_string(crop_top) + " bottom=" + std::to_string(crop_top);
}
std::string launch_str = std::string launch_str =
"( v4l2src device=" + cam.device + "( v4l2src device=" + cam.device +
" ! video/x-raw,format=NV12,width=" + std::to_string(cam.width) + " ! video/x-raw,format=NV12,width=" + std::to_string(cam.width) +
",height=" + std::to_string(cam.height) + ",height=" + std::to_string(cam.height) +
",framerate=" + std::to_string(cam.fps) + "/1" ",framerate=" + std::to_string(cam.fps) + "/1"
" ! queue max-size-buffers=4 leaky=2" // 新增 queue防止阻塞 " ! queue max-size-buffers=4 leaky=2"
" ! videoconvert" " ! videoconvert"
" ! video/x-raw,format=NV12" // 固定转换后的格式 " ! video/x-raw,format=NV12" +
" ! queue max-size-buffers=4 leaky=2" // 再加一层 queue隔离 mpph264enc videocrop_str +
" ! mpph264enc" " ! queue max-size-buffers=4 leaky=2"
" ! rtph264pay name=pay0 pt=96 )"; " ! mpph264enc"
" ! rtph264pay name=pay0 pt=96 )";
GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new(); GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new();
gst_rtsp_media_factory_set_launch(factory, launch_str.c_str()); gst_rtsp_media_factory_set_launch(factory, launch_str.c_str());