ffmpeg not beeing used even if activated

Previous development branch now released as 1.36
Locked
tomcat84
Posts: 39
Joined: Fri Jul 03, 2020 11:24 pm

ffmpeg not beeing used even if activated

Post by tomcat84 »

Hi I have following problem.
I'm using zoneminder 1.35.5 on Ubuntu 18.04 LTS on a j4105 Mainboard with intel i915 graphic card.
If I use Source Type Remote I have a CPU load around 40-50%.
Thats why i want to use ffmpeg.
The Stange thing is if im using it I have CPU Load up to 90-100%.
If I'm checking how its started by using
ps -auxww | grep www-data
its not even in the process list.
www-data 7411 0.1 0.2 418436 22988 ? S 01:13 0:01 /usr/sbin/apache2 -k start
www-data 8246 0.0 0.2 418392 22708 ? S 01:20 0:00 /usr/sbin/apache2 -k start
www-data 8305 0.0 0.2 104924 18132 ? S 01:20 0:00 /usr/bin/perl -wT /usr/bin/zmdc.pl startup
www-data 8334 50.4 10.5 1295180 819536 ? SL 01:20 4:37 /usr/bin/zmc -m 7
www-data 8342 0.0 0.4 127936 37360 ? S 01:20 0:00 /usr/bin/perl -wT /usr/bin/zmfilter.pl --filter_id=1 --daemon
www-data 8348 0.0 0.4 128072 37596 ? S 01:20 0:00 /usr/bin/perl -wT /usr/bin/zmfilter.pl --filter_id=2 --daemon
www-data 8354 0.0 0.2 102324 21972 ? S 01:20 0:00 /usr/bin/perl -wT /usr/bin/zmwatch.pl
www-data 8360 0.0 0.3 113172 26904 ? S 01:20 0:00 /usr/bin/perl -wT /usr/bin/zmupdate.pl -c
www-data 8364 0.0 0.2 102060 21760 ? S 01:20 0:00 /usr/bin/perl -wT /usr/bin/zmstats.pl
www-data 8380 0.0 0.2 418348 22664 ? S 01:20 0:00 /usr/sbin/apache2 -k start
www-data 8382 81.1 11.8 1382428 924112 ? SL 01:20 7:21 /usr/bin/zma -m 7
www-data 8439 0.0 0.2 418344 22372 ? S 01:21 0:00 /usr/sbin/apache2 -k start
www-data 8440 0.0 0.2 418388 22684 ? S 01:21 0:00 /usr/sbin/apache2 -k start
www-data 8483 17.6 9.8 1290448 765352 ? SL 01:22 1:18 /usr/lib/zoneminder/cgi-bin/nph-zms
www-data 8502 0.0 0.2 418388 22700 ? S 01:22 0:00 /usr/sbin/apache2 -k start
www-data 8504 0.0 0.3 418352 24548 ? S 01:22 0:00 /usr/sbin/apache2 -k start
www-data 8659 0.0 0.2 418412 22792 ? S 01:25 0:00 /usr/sbin/apache2 -k start
www-data 8816 0.1 0.2 418088 19464 ? S 01:28 0:00 /usr/sbin/apache2 -k start
www-data 8868 0.0 0.2 417836 17468 ? S 01:29 0:00 /usr/sbin/apache2 -k start
www-data 8869 0.0 0.2 418184 21820 ? S 01:29 0:00 /usr/sbin/apache2 -k start
www-data 8870 0.0 0.2 418184 21820 ? S 01:29 0:00 /usr/sbin/apache2 -k start
So I checked options->images
PATH_FFMPEG is /usr/bin/ffmpeg
I just wrote /dev/null into it for testing its the same result....
FFMPEG_INPUT_OPTIONS I want to use
-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi
cause if I use
/usr/bin/ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i rtsp://admin:password@192.168.2.67:554//h264Preview_01_main -c:v h264_vaapi -f rawvideo -y /dev/null
I have just a cpu load around 2-4% what is realy nice.
/usr/bin/ffmpeg -hwaccels
ffmpeg version 4.3-2ubuntu0~18.04.sav0 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version='2ubuntu0~18.04.sav0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-crystalhd --enable-libmfx --enable-nvenc --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Hardware acceleration methods:
vdpau
cuda
vaapi
qsv
drm
opencl
The logs are spammed with
zmc_m7 8334 WAR RTP: PT=60: bad cseq ba66 expected=1b93 zm_ffmpeg.cpp 70
/dev/dri$ ls -l
drwxr-xr-x 2 root root 80 Jul 4 00:37 by-path
crw-rw----+ 1 root video 226, 0 Jul 4 01:51 card0
crw-rw----+ 1 root video 226, 128 Jul 4 00:37 renderD128
/dev/dri$ members video
www-data
Any Ideas why ffmpeg is not used by zoneminder?
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: ffmpeg not beeing used even if activated

Post by SteveGilvarry »

Zoneminder uses ffmpeg libraries libavformat etc, not the CLI ffmpeg program. The running components zmc and zma for each monitor are what are using those libraries and where you will see any impact in cpu usage. Changing source type changes what libraries these components use in the background.
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
tomcat84
Posts: 39
Joined: Fri Jul 03, 2020 11:24 pm

Re: ffmpeg not beeing used even if activated

Post by tomcat84 »

Ah ok tnx for explanation.
But why is the ffmpeg performance from zoneminder so bad compared to running it from command line :(
Any Ideas?
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: ffmpeg not beeing used even if activated

Post by SteveGilvarry »

It is always decoding, even in monitor mode for use in Live view. Need a new Live view method so we can pass a stream to browser without decoding first. In your CLI example I think you are only copying the video stream, which is exactly what we do for writing the stream to a file, but after that ZMA gets involved and decodes it.

Also the options you were looking at under images are used for export functions that take the old stored jpeg method and exports to a video using ffmpeg cli.
The options you want for for hwaccel and -hwaccel_device are on Source tab of monitor setup, still early days for that and people get mixed results. CPU is either decoding it or copying it in and out of the GPU, so your mileage may vary on using it.

On the Source tab are you using UDP? I think those log entries are due to UDP, takes the traffic in whatever order it arrives and nothing in ffmpeg libraries is re-ordering them. Try Method TCP see if that slows them down.
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
tomcat84
Posts: 39
Joined: Fri Jul 03, 2020 11:24 pm

Re: ffmpeg not beeing used even if activated

Post by tomcat84 »

Ah ok I understand.

I was using TCP.
However when im using Source Type ffmpeg instead of Rempote I get artifacts up to whole screen.
Image

DecoderHWAccelName vaapi
DecoderHWAccelDevice /dev/dri/renderD128

+ high cpu up to 90~ CPU Load on one core for zmc
and ~10 CPU Load on one core for zma without artefacts and up to 90 if artefacts appear

DecoderHWAccelName vaapi
DecoderHWAccelDevice "empty"

same as above

DecoderHWAccelName "empty"
DecoderHWAccelDevice "empty"

same as above

Source Remote:
No artifacts
zmc ~40 CPU Load on one core
zma ~20 CPU Load on one core
Locked