ZM hardware video accelerated

Add any particular hints or tricks you have found to help with your ZoneMinder experience.
Post Reply
User avatar
zd59
Posts: 102
Joined: Wed Jan 18, 2017 1:39 pm
Location: EU - Slovenia

ZM hardware video accelerated

Post by zd59 »

Hi!

As all modern Intel CPUs contain hardware video acceleration and it is supported in ffmpeg, I wonder, how to enable that in ZM to offload CPU.
It's about h.264 and h.265 video streams processing, and https://trac.ffmpeg.org/wiki/Hardware/QuickSync

Any idea?
XabiX
Posts: 13
Joined: Thu Feb 02, 2017 4:31 pm

Re: ZM hardware video accelerated

Post by XabiX »

Hello

I am interested to know as I was using ZM but my CPU with 5 CAMs was 80% with an i7 7700 so I was either thinking to buy an external video card which I am not sure should bring that much optimization if ZM was using intel HD.

Maybe I need to install Windows with Blue Iris as it seems to be working with intel HD but I hate Windows for servers :)

Merci
XabiX
User avatar
zd59
Posts: 102
Joined: Wed Jan 18, 2017 1:39 pm
Location: EU - Slovenia

Re: ZM hardware video accelerated

Post by zd59 »

Hi XabiX!

As I later discovered, ZM do not have any video acceleration options to set up. All is done in ffmpeg dependent library.
The library must be recent and HW acceleration must be enabled at compile time. Distribution I use did not have HW acceleration enabled, so I asked the ffmpeg lib mantainer add that - done in a days!

CPU usage highly depends of ZM settings for camera. Modern h.265 video codec is "Zoneminders CPU killer". Do not use it. Best is mjpeg or h.264.
ZM uses jpeg pictures for a motion detection and events recording. Take a look into events folder. So video from camera must be transformed to jpeg.
To lower CPU usage select source = remote or ffmpeg in camera setup. Also select 32 bit Target color space. To additional offload, you select low FPS. It's enough to have 5 FPS.
To further offload CPU, for a motion detection and record, I setup low resolution camera stream (VGA or PAL) for a moton detection, and link to it "nodect" high resolution camera video stream. And for a motion detection try to create minimum possible zones (and they should be small).

The above is my experience and tests with ZM-1.30.0 on Debian with two cameras, one 3MP h.264 and one with 4MP h.265.
Take a look a 24 hour (snapshot right now) CPU load on my system. CPU: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz with 8GB RAM and SSD disk for OS, events are stored on USB3 attached HD

I'm interested of success of my optimisation method, so please report the results here, if you are willing to use them.

Regards
Attachments
Kernel_load.jpg
Kernel_load.jpg (58.53 KiB) Viewed 15566 times
XabiX
Posts: 13
Joined: Thu Feb 02, 2017 4:31 pm

Re: ZM hardware video accelerated

Post by XabiX »

Bonjour ZD59,

I am under Ubuntu 16.04.3 and using the default library ffmpeg version 7:3.2.4-2~xenial maintained by djcj@gmx.de. Not sure if this is really the one which includes or not HW decoding. My CPU is an i7-7700T which should normally be overkilled.

At the moment my CAMs network is down and didn't receive the new ones so I can do test but I will report. I am also using the MaxFPS to 26 (and ffmpeg with 24bits color).

I did solve quite some issues with the CPU yesterday evening (viewtopic.php?t=25790) so I am now just looking to get the POE switch back so I can test:).

Still running too high for not much but will test with the cameras:

Code: Select all

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                                                                                          
 4990 www-data   20   0  637M  207M  192M S [b]20.4[/b]  1.3  2h50:34 /usr/bin/zmc -m 5                                                                                                                                                                                
 5129 www-data   20   0  637M  204M  192M S [b]19.7[/b]  1.3  2h50:31 /usr/bin/zmc -m 7
 5161 www-data   20   0  637M  205M  192M S [b]19.7[/b]  1.3  2h50:43 /usr/bin/zmc -m 8
 5018 www-data   20   0  637M  207M  192M S [b]19.7[/b]  1.3  2h51:25 /usr/bin/zmc -m 6
Total load 1.19 with no cameras :)

Thanks for sharing your findinds. And hopefully with the right library I should be all set too!

For me the cameras do the detection and record through samba when they detect an event. So I am using ZM as a central management viewer. So even less demanding. If CPU goes down I may do the zones and detections in ZM.

Merci and have a good WE
XabiX
dinskuns
Posts: 4
Joined: Mon Oct 15, 2018 9:13 am

Re: ZM hardware video accelerated

Post by dinskuns »

Have any one succeeded to manage video stream on zm through ffmpeg with hardware acceleration to offload cpu?
User avatar
zd59
Posts: 102
Joined: Wed Jan 18, 2017 1:39 pm
Location: EU - Slovenia

Re: ZM hardware video accelerated

Post by zd59 »

Hardware video acceleration on ZoneMinder (zoneminder as of >= 1.32.2):
The answer from developers: Video manipulation is controlled by ffmpeg.
So the answer is:

Code: Select all

if ffmpeg is compiled with HW acceleration in my distribution then
   zoneminder is HW accelerated  :D 
else
   zoneminder is NOT HW accelerated  :cry: 
endif
So check ffmpeg, to get correct answer.
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

Re: ZM hardware video accelerated

Post by snake »

zd59 wrote: Wed Dec 12, 2018 9:34 am Video manipulation is controlled by ffmpeg.
So the answer is:

Code: Select all

if ffmpeg is compiled with HW acceleration in my distribution then
   zoneminder is HW accelerated  :D 
else
   zoneminder is NOT HW accelerated  :cry: 
endif
Look at the source code. From my understanding Libavcodec is used for the "ffmpeg method" recording of streams, and the ffmpeg binary is used for the optional exporting (as of 1.28 - 1.30.4. not sure about 1.32+). Simply compiling the binary with hw accel isn't enough.

If you want to see if hw accel is active, as I said in my notes here you can set debugging on zmc_m#, and you should see hw accel in the logs. So far, RPI3 is the only platform with acceleration enabled. See: viewtopic.php?f=36&t=25899&p=105296.

H264 Passthrough in 1.32.2 is an option that will decrease load.
Post Reply