resize image before processing

Forum for questions and support relating to the 1.29.x releases only.
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

resize image before processing

Post by evolotion »

Not a feature request (as im sure the devs have their hands full!!) but looking for a suggestion how to achieve.

Have 2 5mp cameras throwing data at a little J1900 quad core celeron, Origionally bought the cameras with the intention of just running them at 1080p however noticed that when set to this the image crops rather than rescales so you loose a lot of the field of view. rescaling the 5mp output is a lot sharper and clearer than running the camera at 1080p also. at 5mp native the image isnt the best but scaled to 1080p it is really sharp.

So what Im asking is, isthere a way to scale the camera output before recording/monitoring or inspecting for motion detection? Im not a total noob with coding and scripting but is this even achievable before I go poking around?

the cheaper these multi mega pixel cameras get the more of this will crop up I imagine, as is at 10fps the system has a load average of 3-3.5 with one core occationally going flat out tho the load is usually fairly well balanced. even with both cameras set just to record the load average is above 2.

With cameras running at 1080p the load average hovered around .8-1.5, quite a difference!
bbunge
Posts: 2930
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: resize image before processing

Post by bbunge »

Camera make/model?
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

white box unbranded cheapest of the cheap.
Closest to branding it has is subscription to a "seetong" cloud service which is disabled and blocked by me.

camera is based around the TI DM368 dsp and i opened them to confirm they are also 5mp sensors. I am aware many cameras are based on this DSP so may have a play flashing different firmwares see if I get lucky and find one that provides a scaling rather than cropping output at 1080p.

I am also aware if I had bought a decent camera I wouldnt be facing this workaround, but where is the fun in that. :mrgreen:
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: resize image before processing

Post by knight-of-ni »

ZoneMinder is hard coded to the following maximum resolution in the source code:
https://github.com/ZoneMinder/ZoneMinde ... g.h.in#L39

Those dimensions work out to 3MP. I've never tried to exceed that, but I certainly would not expect anything larger than that to work properly.

To answer your question, ZoneMinder does not modify the dimensions of the incoming stream so any scaling has to be done in the camera. Since most cameras can support multiple streams, one can do tricks with two monitors, using two different streams at two different resolutions, to achieve different results.

Also note that, you've got to tell ZoneMinder the exact resolution, to the pixel, or you can get cropping or duplication or no image at all. Use VlC player to determine the exact resolution if you have not already.

If you need further assistance, we need to see exactly how you programmed these cameras. Screenshots of your general and source tabs are preferred. Knowing what distro you are on, and what version of ffmpeg and/or vlc you have, would help too.
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/
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

Images captured are 2592x1920. The cameras do support multiple streams except when running in 5mp mode. then there is only one stream.

This image is a direct capture, please forgive the mess of my little workshop.
Image

Camera settings:

source Ffmpeg

Source Path rtsp://192.168.0.51/mpeg4
Remote Method rtp/rtsp
Options (?)
Target colorspace 24bit
Capture Width (pixels) 2592
Capture Height (pixels) 1920
Preserve Aspect Ratio no
Orientation normal
Deinterlacing disabled


Sorry perhaps theres crossed wires, but zoneminder is working great, records events and is stable.

My issue is the camera provides best field of view at 5mp. I wish to record, monitor and analyse events at 1080p . I feel the extra cpu cycles spent resizing the stream will benefit the system overall. I could be wrong but I would like to try it. am currently running at 4fps to prevent the computer being brought to its knees.
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

Apologies photobucket scales the picture but take my word for it its 2592x1920 :)
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: resize image before processing

Post by knight-of-ni »

Well that's interesting. The link I posted shows ZoneMinder's hard-coded maximum dimensions are 2048x1536.
I would not expect anything larger than those dimensions to work, but then again I've never tried.

Oh, change your color space to 32bit. It'll give you a performance boost.

To analyse at a lower resolution than what you view, program two monitors for the same camera. The camera may require a different url for each stream. Set the high resolution camera to monitor mode, and then set the lower resolution to modect mode. Edit your motion zone to cover only the areas you are interested in. This will save some processing. If you want the higher resolution camera to record based on motion in the lower resolution feed, then link the two cameras.

Alternatively, you could add a PIR motion detector in that room to trigger recording.

Hope that helps.

Oh, and because you've got the camera pointing at a door, the image at the door will get washed out anytime someone goes through it. Perhaps you've realized that already. It is usually best to keep exterior doors, windows, and light sources out of the field of view, but I don't know how easy it would be for you move the camera.
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/
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

Appreciate your time, am fairly new to zoneminder and cctv in general.

Washout on the door is an issue as pointed out, however at night anyone entering is nice and clear, and when the shutters are open (when a junkie is most likely to be an oportunist and grab something) the camera adjusts and the view out to the street is lovely and clear. The shutters open directly onto a main road with lots of passing traffic and foot-fall.

32 bit mode set :)

Sadly when the camera main feed is set to 5MP, the sub feed is disabled. this is an annoying limitation in the camera so I cannot process on the sub feed.
I have yet to play with the cameras built in triggering but would very much like to keep everything in zoneminder as it works really well, and provides a central location for configuration rather than finding a windows laptop to load IE to load the proprietary camera configuration application.

I know vlc can be used for transcoding streams so may try get the cameras working with libvlc then see if I can get it to scale the feed down before handing it over to the zoneminder capture daemon.
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: resize image before processing

Post by knight-of-ni »

Oh right, you did say the second stream was not available at 5mp. Well, you could add a second, low res camera.

How techy are you?
ZoneMinder has a daemon called zmtrigger, and as the name implies, it allows you to trigger events via external devices. For example, you could wire a door status contact at that door to an input on an Arduino or an ESP8266. The Arduino/esp8266 would then tell ZoneMinder when to record. You could add a cheap PIR motion detector in the same manner.
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/
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

your sig piqued my interest, have used esp8266 for a few little things but when it comes to security/stability K.I.S.S is the way forward for me so a hard wired PIR would be good. the unit has PIR, shutter sensors and so on but the alarm is a closed box and I dont think the landlord would appreciate me hacking it about lol All that said I would still very much like to find a software solution, part as a learning experience and part as it feels the most elegant solution.
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

Just to update incase anyone else is looking to do the same (search turned up a few folk asking in the past) It turns out this is insanely simple to achieve.
Libvlc seemed a little too buggy and laggy for me (may try again another day) but ffmpeg also has options for scaling on the fly, to that end:-
zoneminder123.jpg
zoneminder123.jpg (74.82 KiB) Viewed 7198 times
scale=-1:1080 << this part meens scale to *something* by 1080 pixels but maintaining aspect ratio. the -1 denotes the something. you could hard code both width and height but aparently this is the way to do it as maintaining aspect ratio makes ffmpegs life easier

-crf 0 << this part sets highest quality possible, have a google to see what other options are avaliable, I will be waiting untill next daylight to experiment.

now the size requires a little maths, we know the source was 2592x1920 we know the new width will be 1080 so the new height is (1080/1920)*2592 i.e.1458

already the average load has dropped to 1.7 ish i will need to wait untill tomorow with some sunlight, events and can get a windows computer to up the framerate and see how she copes.
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: resize image before processing

Post by knight-of-ni »

Hey wow. Look at that. Nice work.
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/
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

Another followup. woke up to a bazillion false events where the bottom half of the screen goes blurry which usually happens if ffmpeg isnt happy with some settings I have chosen, framerate. bitrate etc. and when sunlight came up and I wandered around the unit the load average jumped above 4 (on a 4 core processor) and thats at 4fps. not ideal.

Have changed over to "remote" rather than ffmpeg image seems stable, cpu load dropped (tho we shall se how that pans out today) there is no field to pass commands to remote so previous scaling trick doesnt work. interestingly just putting smaller dimensions into the capture width and height boxes scaled great. However there is a downside, large motion events cauze ZMA to max out one core of the CPU, this never happened with ffmpeg will need to experiment further as "remote" certainly seems more stable than ffmpeg.
evolotion
Posts: 46
Joined: Mon Aug 01, 2016 9:03 pm

Re: resize image before processing

Post by evolotion »

EDIT -- scratch that my zoneminder installation has now became really unstable. will have to sort first (loads of socks errors) before continuing.
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: resize image before processing

Post by knight-of-ni »

evolotion wrote:Another followup. woke up to a bazillion false events where the bottom half of the screen goes blurry which usually happens if ffmpeg isnt happy with some settings I have chosen
This symptom is fairly common using the ffmpeg source type with high resolution cameras. See other forum topics that mention tearing or corrupted video. The root cause seems to be ffmpeg itself, but there are workarounds. It has been discussed in several places, but this is the one that talks about the workarounds: https://github.com/ZoneMinder/ZoneMinder/issues/811

The first thing you should do is change your stream from UDP to TCP. If that doesn't do it, then you need to start messing with certain buffers.

This problem is also possible from within the camera itself. One of my cameras had this issue. The way to tell is to point vlc at the camera after the problem shows itself in ZoneMinder. If they both appear corrupted, then the problem is with the camera. You need to lower the bit rate, either directly (if the camera has the ability to change it) or indirectly by lowering the resolution.
evolotion wrote: However there is a downside, large motion events cauze ZMA to max out one core of the CPU, this never happened with ffmpeg will need to experiment further as "remote" certainly seems more stable than ffmpeg.
Yeah, the remote type has been maintained by iconnor and I, using just a few cameras. Despite well written standards, it seems every camera manufacturer implements the standards a little differently, which messes up the remote source type. The short story is that it is the least compatible of the three source types (ffmpeg, remote, libvlc). Due to other, better priorities, it is unlikely this method will get any more love in the future. Maintaining the other two source types gets us more bang for the buck.
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/
Locked