Problems with "Encode" Video Writer on Ubuntu 16.04

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
mhstar89
Posts: 5
Joined: Sun Dec 17, 2017 2:48 pm

Problems with "Encode" Video Writer on Ubuntu 16.04

Post by mhstar89 »

(I'm aware that standard support on Ubuntu 16.04 has ended, so if that is the reason, let me know.)

Anyway - ever since I upgraded zoneminder, many of my cameras that are set to "Encode" don't actually record a working video. I first thought it was a problem with 1.37, but it occurs on 1.36.3 too.

The cameras on "Camera Passthrough" work fine. Changing the video writer of a camera that causes issues with "Encode" to "Camera Passthrough" allows it to work once more, so there's a workaround, I'm in no rush or pressure to have it fixed.

As for the "Encode" video writer - when it happens:

1. The mp4 created is unrealistically small:

Code: Select all

> /var/cache/zoneminder/events/6/2021-05-31/471044# ls -l
total 176
-rw-r--r-- 1 www-data www-data 28528 May 31 01:16 471044-video.mp4
-rw-r--r-- 1 www-data www-data 69769 May 31 01:15 alarm.jpg
-rw-r--r-- 1 www-data www-data  1310 May 31 12:44 snapshot-64x36.jpg
-rw-r--r-- 1 www-data www-data 69769 May 31 01:15 snapshot.jpg
2. ffprobe says this about the file:

Code: Select all

> /var/cache/zoneminder/events/6/2021-05-31/471044# ffprobe -i 471044-video.mp4
ffprobe version 2.8.17-0ubuntu0.1 Copyright (c) 2007-2020 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '471044-video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2iso6mp41
    title           : Zoneminder Security Recording
    encoder         : Lavf56.40.101
  Duration: 00:00:25.00, start: 0.000000, bitrate: 9 kb/s
    Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv), 1280x720, 6 kb/s, 2.04 fps, 2 tbr, 90k tbn, 1000k tbc (default)
    Metadata:
      handler_name    : VideoHandler
3. There's nothing looking amiss in the syslog:

Code: Select all

May 31 01:15:46 cctv zmc_m6[22469]: INF [zmc_m6] [Camera6: 2861 - Gone into alarm state PreAlarmCount: 0 > AlarmFrameCount:1 Cause:Motion Detail]
May 31 01:15:46 cctv zmc_m6[22469]: INF [zmc_m6] [Camera6: 2836 - Opening new event 471044, alarm start]
May 31 01:15:47 cctv zmc_m6[22469]: INF [zmc_m6] [Camera6: 2838 - Gone into alert state]
May 31 01:15:47 cctv zmc_m1[7556]: INF [zmc_m1] [Camera1: 5188000 - Capturing at 8.00 fps, capturing bandwidth 11755bytes/sec]
May 31 01:15:48 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 450 - Analysing at 2.66 fps from 449 - 439=10 / 1622416548.145325 - 1622416544.383980 = 3.761345]
May 31 01:15:49 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 490 - Capturing at 2.65 fps, capturing bandwidth 316029bytes/sec]
May 31 01:15:51 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 460 - Analysing at 2.67 fps from 459 - 449=10 / 1622416551.895749 - 1622416548.145325 = 3.750424]
May 31 01:15:53 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 500 - Capturing at 2.67 fps, capturing bandwidth 319427bytes/sec]
May 31 01:15:55 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 470 - Analysing at 2.71 fps from 469 - 459=10 / 1622416555.586692 - 1622416551.895749 = 3.690943]
May 31 01:15:56 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 510 - Capturing at 2.71 fps, capturing bandwidth 324496bytes/sec]
May 31 01:15:56 cctv zmc_m1[7556]: INF [zmc_m1] [Camera1: 5188000 - Analysing at 8.00 fps from 5187999 - 5186999=1000 / 1622416556.989125 - 1622416432.044394 = 124.944731]
May 31 01:15:59 cctv zmc_m4[22891]: INF [zmc_m4] [Camera4: 480 - Analysing at 2.65 fps from 479 - 469=10 / 1622416559.355822 - 1622416555.586692 = 3.769130]
May 31 01:15:59 cctv zmc_m6[22469]: INF [zmc_m6] [Camera6: 2863 - Left alarm state (471044) - 51(2) images]
May 31 01:15:59 cctv zmc_m6[22469]: INF [zmc_m6] [Camera6: 2863 - Closing event 471044, alarm end]
The only encoder parameter is "crf=23", but removing it changes nothing.
The alarm.jpg and snapshot*.jpg files are valid and show the correct picture with the alarm reason.

Any ideas about where things go wrong?
User avatar
iconnor
Posts: 2931
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Problems with "Encode" Video Writer on Ubuntu 16.04

Post by iconnor »

The size may be ok, you are writing an h265 file. Your browser probably can't play it though.

Unfortunately ffmpeg libs don't necessarily select good options for the encoder. You need to look up good values for the encoder of choice.

This is something I hope to improve but it's a bit tough to build up a matrix of good values.

crf=23 is a basic start. Using libx264 to write h264 mp4s gives total crap without at least a crf value. I use crf=36 and preset=veryfast for most of my encoding.

I suggest being specific about codec choice instead of auto.
mhstar89
Posts: 5
Joined: Sun Dec 17, 2017 2:48 pm

Re: Problems with "Encode" Video Writer on Ubuntu 16.04

Post by mhstar89 »

iconnor wrote: Mon May 31, 2021 1:06 pmThe size may be ok, you are writing an h265 file. Your browser probably can't play it though.
There's something in the file for sure - VLC displays a single frame after playing it for a few seconds.
iconnor wrote: Mon May 31, 2021 1:06 pm I suggest being specific about codec choice instead of auto.
That completely solves my issue. The moment I specify h264, everything works as it used to. Thanks a lot!
Post Reply