diff --git a/src/rtsp_manager.cpp b/src/rtsp_manager.cpp index 3c3928c..0c96561 100644 --- a/src/rtsp_manager.cpp +++ b/src/rtsp_manager.cpp @@ -25,29 +25,21 @@ 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; - int crop_top = (960 - 720) / 2; - videocrop_str = " ! videocrop top=" + std::to_string(crop_top) + " bottom=" + std::to_string(crop_top); - } - + // 构建 pipeline 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) + + " ! video/x-raw,format=NV12,width=" + std::to_string(out_width) + + ",height=" + std::to_string(out_height) + ",framerate=" + std::to_string(cam.fps) + "/1" - " ! queue max-size-buffers=8 leaky=2" + - videocrop_str + - " ! queue max-size-buffers=8 leaky=2" - " ! mpph264enc" - " ! h264parse" - " ! rtph264pay name=pay0 pt=96 )"; + " ! queue max-size-buffers=2 leaky=downstream" + " ! mpph264enc bps=2000000 gop=" + + std::to_string(cam.fps) + " b_frame=0" + " ! h264parse" + " ! rtph264pay name=pay0 pt=96 )"; GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new(); gst_rtsp_media_factory_set_launch(factory, launch_str.c_str());