Use a flag to tell whether we have written the snapshot jpeg yet. If image data has been freed from packets, we may not write the snapshot because we already had a packet with a higher score.

pull/3609/head
Isaac Connor 2022-08-22 14:53:21 -04:00
parent fc2e5aa135
commit 83a2e543f9
2 changed files with 4 additions and 1 deletions

View File

@ -60,6 +60,7 @@ Event::Event(
max_score(-1), max_score(-1),
//path(""), //path(""),
//snapshit_file(), //snapshit_file(),
snapshot_file_written(false),
//alarm_file(""), //alarm_file(""),
videoStore(nullptr), videoStore(nullptr),
//video_name(""), //video_name(""),
@ -450,10 +451,11 @@ void Event::AddFrame(const std::shared_ptr<ZMPacket>&packet) {
} // end if save_jpegs } // end if save_jpegs
// If this is the first frame, we should add a thumbnail to the event directory // If this is the first frame, we should add a thumbnail to the event directory
if ((frames == 1) || (score > max_score)) { if ((frames == 1) || (score > max_score) || (!snapshot_file_written)) {
write_to_db = true; // web ui might show this as thumbnail, so db needs to know about it. write_to_db = true; // web ui might show this as thumbnail, so db needs to know about it.
Debug(1, "Writing snapshot to %s", snapshot_file.c_str()); Debug(1, "Writing snapshot to %s", snapshot_file.c_str());
WriteFrameImage(packet->image, packet->timestamp, snapshot_file.c_str()); WriteFrameImage(packet->image, packet->timestamp, snapshot_file.c_str());
snapshot_file_written = true;
} else { } else {
Debug(1, "Not Writing snapshot because frames %d score %d > max %d", frames, score, max_score); Debug(1, "Not Writing snapshot because frames %d score %d > max %d", frames, score, max_score);
} }

View File

@ -86,6 +86,7 @@ class Event {
int max_score; int max_score;
std::string path; std::string path;
std::string snapshot_file; std::string snapshot_file;
bool snapshot_file_written;
std::string alarm_file; std::string alarm_file;
VideoStore *videoStore; VideoStore *videoStore;