|
|
@@ -246,17 +246,19 @@ public:
|
|
|
"multipart/x-mixed-replace; boundary=mjpegboundary",
|
|
|
[this, fp, seqfn](size_t, httplib::DataSink& sink) -> bool {
|
|
|
uint64_t last_seq = 0;
|
|
|
+ // MJPEG推流节流: 约12fps, 避免并发编码吃满CPU
|
|
|
+ const int interval_ms = 80;
|
|
|
while (!stopping.load() && mjpeg_enabled.load() && sink.is_writable()) {
|
|
|
uint64_t seq = seqfn ? seqfn() : 0;
|
|
|
if (seq != 0 && seq == last_seq) {
|
|
|
// 帧未更新, 跳过重复JPEG编码
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(15));
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
continue;
|
|
|
}
|
|
|
cv::Mat frame = fp->second();
|
|
|
if (!frame.empty()) {
|
|
|
std::vector<uchar> buf;
|
|
|
- std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 60};
|
|
|
+ std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 50};
|
|
|
cv::imencode(".jpg", frame, buf, params);
|
|
|
std::string header = "--mjpegboundary\r\n"
|
|
|
"Content-Type: image/jpeg\r\n"
|
|
|
@@ -266,7 +268,7 @@ public:
|
|
|
if (!sink.write("\r\n", 2)) return false;
|
|
|
last_seq = seq;
|
|
|
}
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(33));
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(interval_ms));
|
|
|
}
|
|
|
return true;
|
|
|
});
|