Image buffer size

Forum for questions and support relating to 1.33.x development only.
Post Reply
andrew-yu
Posts: 19
Joined: Thu Sep 20, 2018 7:50 am

Image buffer size

Post by andrew-yu » Wed Jun 12, 2019 7:24 am

I see many log entries about image buffer size. Now Zoneminder wants buffer size like 400 or 500 for some of my cameras. I haven't so much RAM for that. I already setup minimum keyframe interval on all cameras where i could do it. Can it so large keyframe intervals like 400 or 500? Or can it be any performance issue?

Code: Select all

ImageBufferCount 85 is too small. Needs to be at least 401. Either increase it or decrease time between keyframes

User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Image buffer size

Post by knight-of-ni » Wed Jun 12, 2019 12:38 pm

There is a direct relationship between how often keyframes are sent and memory requirements.

The message you posted indicates the keyframes are coming in way too slowly. A value of 401 is unusually large... double check you are entering the kayframe value in the camera correctly.

Keep in mind, in order to decrease the time between keyframes, you typically need to increase the keyframe value in the camera. I've often found the verbiage in the camera, describing the keyframe field, to either be misleading or absent altogether. Typically the value you enter represents the number of frames to send between each keyframe, so a value of 10 means to send a keyframe after every 10 frames.

If I want 1 keyframe to be sent every second and my cameras is running at 5 fps, then that would typically mean I would need to put a value of 5 in the keyframe field in the camera. If running @7fps, then use a keyframe value of 7, etc.

This can vary per camera, but this is typically what I end up doing.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

warlord
Posts: 11
Joined: Mon Mar 02, 2020 7:01 pm

Re: Image buffer size

Post by warlord » Tue Mar 03, 2020 5:33 pm

I am having a similar issue with my cameras. I've got Besder 1080p PoE cameras and all of them are reporting this issue. As is my Doorbird camera. For doorbird it was telling me "20 is too small, increase to 31". I increased to 35, and now it says "35 is too small, increase to 51". And all my Besder cameras are saying "40 is too small, increase to 51". I can't see how to change this setting at all on the doorbird.

But I've played with these camera configs on the Besders. I am recording from the Besder cameras at 5fps. The "I Frame Interval" was already set to 2. I tried increasing that to 5, but it didn't make a difference. I tried changing from VBR to CBR and going to the highest bitrate, but it didn't make a difference.... unless I need to stop the stream and restart it for the changes to take effect?

I don't have the RAM to increase the buffers -- I've got 32G RAM and I already increased the buffers from the default, 20, to 40 in order to get a longer pre-roll in my events. But right now I'm riding around 93% SHM usage.

BassT
Posts: 1
Joined: Fri Apr 10, 2020 10:14 am

Re: Image buffer size

Post by BassT » Fri Apr 10, 2020 10:31 am

Same Problem here.
I'm on 1.34.7 with 3 WiFi Cams, setup in VM.
Image Buffer Size is set to 30 because of ~5Gig Ram.

Now, where to set (decrease) time between key frames?
Can't find / see the settings, ...

watcherwatcher
Posts: 3
Joined: Fri Jun 05, 2020 2:20 am

Re: Image buffer size

Post by watcherwatcher » Fri Jun 05, 2020 3:01 am

For those who are finding this thread, here's what we know so far:
There was an issue with 1.33.14 that has been reportedly fixed in 1.33.14. https://github.com/ZoneMinder/zoneminder/issues/2682 https://github.com/ZoneMinder/zoneminder/issues/2682

That post suggested increasing "Options->System->WATCH_MAX_DELAY". I've done that, restarted Zoneminder and the same error messages persist (for me, it's "ImageBufferCount 20 is too small. Needs to be at least 31. Either increase it or decrease time between keyframes")

The logs have the source file and line number which produced the error (HUGE thank you to whomever decided to do that!), so I looked at zz_ffmpeg_camera.cpp:941 in the master branch. That is using monitor->GetImageBufferCount() which lives in a .h file, oddly. In zm_monitor.h we see that it just maps to image_buffer_count. This looks like it's being set in zm_monitor.cpp:2150 using atoi(dbrow[col]). There's a helpful comment just above that function which confirms that this data is, in fact, coming from the Monitor table of the database.

Logging into the database, we find that the Monitor table has a field called ImageBufferCount and in my case, it is, in fact set to 20 for each of my cameras. I grepped the source code to see where this field was set, but came up empty handed. Fortunately, after poking around in the camera settings it was obvious: Edit Camera -> Buffers -> Image Buffer Size (frames). I changed it there for each of my cameras, checked the database, and sure enough, it was updated in the Monitor table.

Doing so caused errors to go away. It also caused /dev/shm to jump from 48% to 74%. This increase perfectly matches the ratio of frames I'm holding, so this is the expected increase. You can use this same formula to predict how much additional memory you'll need if you want to increase the buffer, add cameras, and so forth.

If you don't have enough memory, the only other option is to increase keyframes sent by the camera. If your camera doesn't have that option (mine doesn't as far as I can tell), then, as knight-of-ni said, you just need more memory. That's it. There's no way around this.

Hopefully this information will help BassT in finding the Image Buffer Size setting, and it might help others figure out how to trace through the code to find answers to future questions. For the record, if you're wondering if I only found the answer because I was trying to write up the places I looked for this post... yes. I tried to find it earlier and apparently took a wrong turn somewhere, but as soon as I try to explain it to someone else... the answers just become obvious. :P

Best of luck.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest