diff --git a/config.json b/config.json index fc5b64a..0aef9c1 100644 --- a/config.json +++ b/config.json @@ -14,7 +14,7 @@ "device": "/dev/video11", "name": "AHD1", "enabled": true, - "resolution": "720p", + "bitrate": 2000000, "width": 1280, "height": 720, "fps": 30 @@ -23,7 +23,7 @@ "device": "/dev/video12", "name": "AHD2", "enabled": false, - "resolution": "720p", + "bitrate": 2000000, "width": 1280, "height": 720, "fps": 30 @@ -32,7 +32,7 @@ "device": "/dev/video13", "name": "AHD3", "enabled": false, - "resolution": "720p", + "bitrate": 2000000, "width": 1280, "height": 720, "fps": 30 @@ -41,7 +41,7 @@ "device": "/dev/video14", "name": "AHD4", "enabled": false, - "resolution": "720p", + "bitrate": 2000000, "width": 1280, "height": 720, "fps": 30 @@ -50,7 +50,7 @@ "device": "/dev/video3", "name": "AHD5", "enabled": false, - "resolution": "1080p", + "bitrate": 2000000, "width": 1920, "height": 1080, "fps": 30 @@ -59,7 +59,7 @@ "device": "/dev/video2", "name": "AHD6", "enabled": false, - "resolution": "1080p", + "bitrate": 2000000, "width": 1920, "height": 1080, "fps": 30 @@ -68,7 +68,7 @@ "device": "/dev/video1", "name": "AHD7", "enabled": false, - "resolution": "1080p", + "bitrate": 2000000, "width": 1920, "height": 1080, "fps": 30 @@ -77,7 +77,7 @@ "device": "/dev/video0", "name": "AHD8", "enabled": false, - "resolution": "1080p", + "bitrate": 2000000, "width": 1920, "height": 1080, "fps": 30 diff --git a/include/app_config.hpp b/include/app_config.hpp index 963c43c..921eabe 100644 --- a/include/app_config.hpp +++ b/include/app_config.hpp @@ -20,6 +20,7 @@ struct Camera std::string device; std::string name; int width, height, fps; + int bitrate; // 新增码率字段 (bps) bool enabled; }; @@ -95,10 +96,12 @@ struct AppConfig cam.width = c.value("width", 1280); cam.height = c.value("height", 720); cam.fps = c.value("fps", 30); + cam.bitrate = c.value("bitrate", 2000000); cam.enabled = c.value("enabled", false); cfg.cameras.push_back(cam); LOG_INFO("[Config] Loaded camera: " + cam.name + - " (" + cam.device + "), enabled=" + std::to_string(cam.enabled)); + " (" + cam.device + "), enabled=" + std::to_string(cam.enabled) + + ", bitrate=" + std::to_string(cam.bitrate)); } } diff --git a/src/rtsp_manager.cpp b/src/rtsp_manager.cpp index cf17d15..488d83f 100644 --- a/src/rtsp_manager.cpp +++ b/src/rtsp_manager.cpp @@ -36,10 +36,11 @@ GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam) ",height=" + std::to_string(out_height) + ",framerate=" + std::to_string(cam.fps) + "/1" " ! queue max-size-buffers=1 leaky=downstream" // 最小队列 - " ! mpph264enc bps=2000000 gop=" + - std::to_string(cam.fps) + " " // 固定 4Mbps - " ! h264parse" - " ! rtph264pay name=pay0 pt=96 config-interval=1 )"; // 每秒发送 SPS/PPS + " ! mpph264enc bps=" + + std::to_string(cam.bitrate) + + " gop=" + std::to_string(cam.fps) + // GOP 设置为 1 秒 + " ! h264parse" + " ! rtph264pay name=pay0 pt=96 config-interval=1 )"; // 每秒发送 SPS/PPS GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new(); gst_rtsp_media_factory_set_launch(factory, launch_str.c_str());