diff --git a/.vscode/settings.json b/.vscode/settings.json index 52f58b2..c02039a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -63,6 +63,7 @@ "typeindex": "cpp", "typeinfo": "cpp", "valarray": "cpp", - "variant": "cpp" + "variant": "cpp", + "set": "cpp" } } \ No newline at end of file diff --git a/src/rtsp_manager.cpp b/src/rtsp_manager.cpp index ca59b09..eeffdf5 100644 --- a/src/rtsp_manager.cpp +++ b/src/rtsp_manager.cpp @@ -25,17 +25,31 @@ void RTSPManager::init() // 创建 media factory 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 = "( v4l2src device=" + cam.device + " ! video/x-raw,format=NV12,width=" + std::to_string(cam.width) + ",height=" + std::to_string(cam.height) + ",framerate=" + std::to_string(cam.fps) + "/1" - " ! queue max-size-buffers=4 leaky=2" // 新增 queue,防止阻塞 + " ! queue max-size-buffers=4 leaky=2" " ! videoconvert" - " ! video/x-raw,format=NV12" // 固定转换后的格式 - " ! queue max-size-buffers=4 leaky=2" // 再加一层 queue,隔离 mpph264enc - " ! mpph264enc" - " ! rtph264pay name=pay0 pt=96 )"; + " ! video/x-raw,format=NV12" + + videocrop_str + + " ! queue max-size-buffers=4 leaky=2" + " ! mpph264enc" + " ! rtph264pay name=pay0 pt=96 )"; GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new(); gst_rtsp_media_factory_set_launch(factory, launch_str.c_str());