no valid mp4s created

Forum for questions and support relating to the 1.32.x releases only.
keithg
Posts: 4
Joined: Sun Jan 06, 2019 11:26 pm

no valid mp4s created

Post by keithg »

Been struggling with this for a while.

This is version 1.32.3 installed on a freenas install (freebsd). I have tried the 'plugin' and installing the port in a jail and get the same result. I cannot view an 'event'. In monitor mode, I can see both cameras. I select modect for both cameras and events are created. If I select the event , I get a black image which has: "The video could not be loaded, either necause the network or server failed or because the format is not supported." If I go to the actual folder in the directory, I can see a jpg and a mp4 file. I can open the jpg, but the mp4 appears to be corrupted or possibly a container with no content.

When I installed the port, I was given these instructions which I followed:

Code: Select all

Installing zoneminder-1.32.3...
ZoneMinder is a free, open source Closed-circuit television software 
application developed for Unix-like operating systems which supports 
IP, USB and Analog cameras. 

New installs
============

ZoneMinder requires a MySQL (or MySQL forks) database backend and 
a http server, capable to execute PHP and CGI scripts.

To simplify things, we assume, that you use MySQL and NGINX on 
the same server.

1. Preliminary steps

1.1 Install databases/mysql57-server or newer
	You may choose your favourite method - ports or packages here. 

	ZoneMinder use very simple queries, however it tends to write to 
	the database quite a lot depending on your capture mode and number 
	of cameras. So tweak your MySQL instance accordantly

	Now, enable and start MySQL
		sysrc mysql_server_enable="YES"
		service mysql-server start

1.2 Install www/nginx 
	We provide an example for an HTTP install, however, you should use 
	HTTPS if you plan to expose your installation to the public. There 
	are plenty guides how to do it and security/letsencrypt.sh is a 
	good way to get a valid SSL certificate. Probably, your installation
	will be behind reverse proxy, so this example should work for you.

	Please, notive the following issues with ZM:

	- web interface has several hardcoded /zm in url generation, so it is
		mandatory to serve your installtion from /zm subfolder
	- if behind reverse proxy, HTTP_X_FORWARDED_PROTO must be supplied or link
		generation will use http://

	Your server block should include the following:

	server {
		listen 80;

		root /usr/local/www/zoneminder;
		index index.php
		gzip off;

		location /cgi-bin/nph-zms {

			include fastcgi_params;
			fastcgi_param SCRIPT_FILENAME $request_filename;
			fastcgi_pass  unix:/var/run/fcgiwrap/fcgiwrap.sock;
		}

		location /zm/cache {

			alias /var/cache/zoneminder;
		}

		location /zm {

			alias	/usr/local/www/zoneminder;

			location ~ \.php$ {

				if (!-f $request_filename) { return 404; }
				include fastcgi_params;
				fastcgi_param SCRIPT_FILENAME $request_filename;
				fastcgi_index index.php;
				fastcgi_pass unix:/var/run/php-fpm.sock;
			}

			location ~ \.(jpg|jpeg|gif|png|ico)$ {
				access_log	off;
				expires	33d;
			}

			location /zm/api/ {
				alias	/usr/local/www/zoneminder;
				rewrite ^/zm/api(.+)$ /zm/api/app/webroot/index.php?p=$1 last;
			}
		}
	}

	Enable and start NGINX
		sysrc nginx_enable="YES"
		service nginx start

1.3 Install www/fcgiwrap 
	As NGINX lacks it's own CGI wrapper, we need external one. Please 
	note that ZoneMinder's montage page use simultaneous access to all 
	cameras, so you need to use at least as many fcgiwrap workers as 
	your number of cameras. The following example assumes you have 4.

	Enable and start FcgiWrap
		sysrc fcgiwrap_enable="YES"
		sysrc fcgiwrap_user="www"
		sysrc fcgiwrap_socket_owner="www"
		sysrc fcgiwrap_flags="-c 4"

1.4 PHP is installed as a dependency to ZoneMinder. However, you should 
	tweak some of it's settings.
	Edit /usr/local/etc/php-fpm.conf and set

		listen = /var/run/php-fpm.sock
		listen.owner = www
		listen.group = www
		env[PATH] = /usr/local/bin:/usr/bin:/bin

	If you want to set another path for the socket file, make sure you 
	change it in your NGINX config well. The env[PATH] needs to be set 
	to locate the zip utility as ZoneMinder's export functions rely on 
	exec(). Sorry, chroot folks. 

	PHP throws warning if date.timezone option is not set. The best place 
	to do it is to create new ini file in /usr/local/etc/php with overrides

		date.timezone = "UTC"

	Enable and start php-fpm
		sysrc php_fpm_enable="YES"
		service php-fpm start

1.5 ZoneMinder constantly keeps the last N frames from its cameras to 
	preserve them when alarm occurs. This can be a performance hog if 
	placed on spindle drive. The best practice is put it on tmpfs.
	See https://www.freebsd.org/cgi/man.cgi?query=tmpfs for more 
	information.

	ZoneMinder will use /tmp for default. If you plan to change it, see 
	ZM_PATH_MAP setting.

	Mapping /tmp to tmpfs is actually a recommended step under FreeBSD.
	Edit /etc/fstab and add the following:

		tmpfs			/tmp		tmpfs	rw,nosuid,mode=01777	0	0

	The size of temporary files depends on your number of cameras 
	number and frames you plan to keep. My 12 3Mbit cameras with 25 
	last frames consumes 6 GB.

2. ZoneMinder installation

	Connect to MySQL under root and create zm user and populate database.

	mysql -u root -p
	
		CREATE DATABASE zm;
		GRANT ALL PRIVILEGES ON zm.* TO 'zmuser'@'localhost' IDENTIFIED BY 'zmpass';
		FLUSH PRIVILEGES;
		quit;
	
	mysql -u root -p zm < /usr/local/share/zoneminder/db/zm_create.sql
	
2.1 If you have chosen to change the ZoneMinder MySQL credentials to something
	other than zmuser/zmpass then you must now edit /usr/local/etc/zm.conf. Change
	ZM_DB_USER and ZM_DB_PASS to the values you created in the previous step.

	Enable and start ZoneMinder
		sysrc zoneminder_enable="YES"
		service zoneminder start

Upgrades
========

1. Stop ZoneMinder
	service zoneminder stop

2. Upgrade database
	sudo -u www zmupdate.pl
	
3. Start ZoneMinder
	service zoneminder start

Upgrading from www/zoneminder 1.30.x or www/zoneminder-h264
=====================================================

Before proceeding to upgrade sequence listed above,

1. Connect to mysql server with root and issue
	set global log_bin_trust_function_creators=1;

2. Add write access to www user to /usr/local/etc/zoneminder/zmcustom.conf

3. Take notice, that default monitor files are not under ${WWWDIR} anymore.
	Old setup will work, but as security concideration it is recommended to
	move them to /var/db/zoneminder (default) or to any place not under www root.

===> SECURITY REPORT: 
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/www/zoneminder/cgi-bin/zms
/usr/local/bin/zmu
/usr/local/bin/zma
/usr/local/bin/zmc

      This port has installed the following startup scripts which may cause
      these network services to be started at boot time.
/usr/local/etc/rc.d/zoneminder

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage: 
https://www.zoneminder.com/
There is one mistake in instructions that the version of zoneminder needs mysql56-server and not mysql57-server. When I tried that, I got a mismatched library version and many errors. Currently. it all looks like it is working from the 'Console' page even with green cameras and log... I can add cameras and they show up green and selecting any of them show the current video. I cannot review any recorded events, though.

In the log, I get these messages:

Code: Select all

2019-01-06 23:34:06.759310 zmdc[98783].ERR-zmdc.pl ['zma -m 1' exited abnormally, exit status 255]
2019-01-06 23:34:06.743643 zma_m1[101877].ERR-zm_monitor.cpp/477 [Shared data not initialised by capture daemon for monitor IPCAM]
2019-01-06 23:23:23.456989 zmc_m2[101922].ERR-zm_remote_camera_http.cpp/1096 [Unable to get response, disconnecting]
2019-01-06 23:23:23.387776 zmc_m2[101922].ERR-zm_remote_camera_http.cpp/956 [Unable to read subheader]
2019-01-06 23:23:23.370970 zmc_m2[101922].ERR-zm_remote_camera_http.cpp/212 [Select error: Interrupted system call]
2019-01-06 23:16:15.144281 web_php[95029].FAT-views/image.php/179 [Can't create frame images from video for this event (61-video.mp4]
2019-01-06 23:16:14.950557 web_php[95030].ERR-includes/Event.php/415 [Capture file does not exist at /var/db/zoneminder/events/1/2019-01-06/61/00007-capture.jpg]
2019-01-06 23:16:14.345434 web_php[95030].FAT-views/image.php/179 [Can't create frame images from video for this event (61-video.mp4]
2019-01-06 23:16:14.025948 web_php[95029].FAT-views/image.php/179 [Can't create frame images from video for this event (61-video.mp4]
2019-01-06 23:16:13.875971 web_php[95030].ERR-includes/Event.php/415 [Capture file does not exist at /var/db/zoneminder/events/1/2019-01-06/61/00006-capture.jpg]
bbunge
Posts: 2930
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: no valid mp4s created

Post by bbunge »

Many of us have tried and failed to get Zoneminder working successfully with NGINX. I've been working on LEMP using Ubuntu 18.04, Mariadb, NGINX, PHP-FPM and ZM 1.32.3 most of the weekend.

My recommendation is to use Apache2 and not NGINX. Of course someone will counter me and say it works... GREAT! Show us your config for NGINX!!!
keithg
Posts: 4
Joined: Sun Jan 06, 2019 11:26 pm

Re: no valid mp4s created

Post by keithg »

I got the nginx.conf from the zoneminder jail. Nginx is what installs when you install the freebsd zoneminder port or package as a dependency of zoneminder. Apache does not install automatically. Like I said, it mostly works, just no recording in an mp4 of a motion detected event which sounds like some dependency is not installed or maybe a location of a dependency not correct in my configuration. In FreeBSD, for all packages which are user installed, the installed binaries are in /usr/local/bin and configurations in /usr/local/etc and not /bin or /usr/bin or /etc.

edit: Read the instructions I posted as you need to install fcgiwrap (whatever it is under your linux package manager) and edit the php.ini as well...

My nginx.conf is:

Code: Select all

#
#    FreeNAS nginx configuration file
#

load_module /usr/local/libexec/nginx/ngx_http_uploadprogress_module.so;

user www www;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    # reserve 1MB under the name 'proxied' to track uploads
    upload_progress proxied 1m;

    sendfile        on;
    #tcp_nopush     on;
    client_max_body_size 1000m;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    # Disable tokens for security (#23684)
    server_tokens off;

    #gzip  on;
    #upload_store /var/tmp/firmware;
    client_body_temp_path /var/tmp/firmware;

    error_log syslog:server=unix:/var/run/log,nohostname;
    access_log syslog:server=unix:/var/run/log,nohostname;

    upstream netdata {
        # the netdata server
        server 127.0.0.1:19999;
        keepalive 64;
    }

    
    server {
        server_name  localhost;
	listen			192.168.2.198:443 default_server ssl http2;
	listen			[::]:443 default_server ssl http2;

	ssl_certificate		"/etc/certificates/freenas-pre-certui.crt";
	ssl_certificate_key	"/etc/certificates/freenas-pre-certui.key";
	ssl_dhparam "/data/dhparam.pem";

	ssl_session_timeout	120m;
	ssl_session_cache	shared:ssl:16m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_prefer_server_ciphers on;
	ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EDH+aRSA:EECDH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS;
	add_header Strict-Transport-Security max-age=31536000;

	## TODO: OCSP Stapling
	#ssl_stapling on;
	#ssl_stapling_verify on;
	#resolver ;
	#ssl_trusted_certificate ;

        location / {
            rewrite ^.* /ui/;
        }

        location ~ ^/(legacy|plugins|api/v1.0)/ {
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9042;
            fastcgi_pass_header Authorization;
            fastcgi_intercept_errors off;
            fastcgi_read_timeout 600m;
            #fastcgi_temp_path /var/tmp/firmware;
            fastcgi_param HTTPS $https;

            # track uploads in the 'proxied' zone
            # remember connections for 30s after they finished
            track_uploads proxied 30s;
        }

        location /progress {
            # report uploads tracked in the 'proxied' zone
            report_uploads proxied;
        }

        location ^~ /legacy/static {
            alias /usr/local/www/freenasUI/static;
            add_header Cache-Control "must-revalidate";
            add_header Etag "FreeNAS-11.2-RELEASE-U1 (31f889bbf)";
        }

        location ^~ /legacy/dojango/dojo-media/release/1.12.2 {
            alias /usr/local/www/dojo;
        }

        location /api/docs {
            proxy_pass http://127.0.0.1:6000/api/docs;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header X-Script-Name /api/docs;
        }

        location /api/docs/restful/static {
            alias /usr/local/www/swagger-ui/node_modules/swagger-ui-dist;
        }

        location /ui {
            if ( $request_method ~ ^POST$ ) {
                proxy_pass http://127.0.0.1:6000;
            }
            try_files $uri $uri/ /index.html =404;
            alias /usr/local/www/webui;
        }

        location /netdata {
            return 301 /netdata/;
        }

       location ~ ^/netdata/(?<ndpath>.*) {
            proxy_redirect off;
            proxy_set_header Host $host;

            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_pass_request_headers on;
            proxy_set_header Connection "keep-alive";
            proxy_store off;
            proxy_pass http://netdata/$ndpath$is_args$args;

            gzip on;
            gzip_proxied any;
            gzip_types *;
        }

        location /websocket {
            proxy_pass http://127.0.0.1:6000/websocket;
            proxy_http_version 1.1;
            proxy_set_header X-Real-Remote-Addr $remote_addr;
            proxy_set_header X-Real-Remote-Port $remote_port;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        location /websocket/shell {
            proxy_pass http://127.0.0.1:6000/_shell;
            proxy_http_version 1.1;
            proxy_set_header X-Real-Remote-Addr $remote_addr;
            proxy_set_header X-Real-Remote-Port $remote_port;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_send_timeout 7d;
            proxy_read_timeout 7d;
        }

        location /api/v2.0 {
	    # do not add the path to proxy_pass because of automatic url decoding
	    # e.g. /api/v2.0/pool/dataset/id/tank%2Ffoo/ would become
	    #      /api/v2.0/pool/dataset/id/tank/foo/
            proxy_pass http://127.0.0.1:6000;
            proxy_http_version 1.1;
            proxy_set_header X-Real-Remote-Addr $remote_addr;
            proxy_set_header X-Real-Remote-Port $remote_port;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $remote_addr;
        }

        location /_download {
            proxy_pass http://127.0.0.1:6000;
            proxy_http_version 1.1;
            proxy_set_header X-Real-Remote-Addr $remote_addr;
            proxy_set_header X-Real-Remote-Port $remote_port;
        }

        location /_upload {
            # Allow uploads of any size. Its middlewared job to handle size.
            client_max_body_size 0;
            proxy_pass http://127.0.0.1:6000;
            # make sure nginx does not buffer the upload and pass directly to middlewared
            proxy_request_buffering off;
            proxy_http_version 1.1;
            proxy_set_header X-Real-Remote-Addr $remote_addr;
            proxy_set_header X-Real-Remote-Port $remote_port;
        }

        location /images {
            alias /var/db/system/webui/images;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

        #include plugins.conf;
    }
    server {
	listen 192.168.2.198:80;
	listen [::]:80;
	server_name localhost;
	return 307 https://$host:443$request_uri;
    }
}
keithg
Posts: 4
Joined: Sun Jan 06, 2019 11:26 pm

Re: no valid mp4s created

Post by keithg »

Still trying to solve this. I checked and can create mp4s from the streams from the command line in the jail so that seems to rule out a missing dependency or something. Is there a setting somewhere? My ffmpeg options are set at default in the 'as installed' port though I do not know what else they could or should be:
my 'ffmpeg formats' are: mpg mpeg wmv asf avi* mov swf 3gp**
My ffmpeg output options are: -r 25
the input options are blank.
Last edited by keithg on Wed Jan 09, 2019 12:33 pm, edited 1 time in total.
abi
Posts: 61
Joined: Fri Oct 23, 2015 11:25 am

Re: no valid mp4s created

Post by abi »

X264 encode camera mode doesn't work in ZM under FreeBSD. All commands succeed, but resulting mp4 containers are empty (they have correct header, but no track). I can't solve this without ZM devs as the issue is definitely in C code. This is not a regression, X264 encode was broken from the beginning.
If they wish to lend me a hand, I can setup test box. I think, fix will be easy, the problem is to find whats wrong.
joster69
Posts: 3
Joined: Wed Jan 09, 2019 10:30 pm

Re: no valid mp4s created

Post by joster69 »

Have the same problem. Empty .mp4 containers.
abi wrote: Wed Jan 09, 2019 6:42 am X264 encode camera mode doesn't work in ZM under FreeBSD. All commands succeed, but resulting mp4 containers are empty (they have correct header, but no track). I can't solve this without ZM devs as the issue is definitely in C code. This is not a regression, X264 encode was broken from the beginning.
If they wish to lend me a hand, I can setup test box. I think, fix will be easy, the problem is to find whats wrong.
pingcam
Posts: 1
Joined: Tue Jan 08, 2019 9:05 am

Re: no valid mp4s created

Post by pingcam »

@abi can this be related?

viewtopic.php?f=38&t=27927#p109118
montagdude
Posts: 88
Joined: Fri Nov 10, 2017 6:05 pm

Re: no valid mp4s created

Post by montagdude »

pingcam wrote: Wed Jan 23, 2019 3:33 pm @abi can this be related?

viewtopic.php?f=38&t=27927#p109118
I think it's different, because in my case no mp4 files were being written at all, and errors were showing up in the logs. But it could possibly be something similar, I guess.
User avatar
llama
Posts: 9
Joined: Sat Jan 05, 2019 4:26 am

Re: no valid mp4s created

Post by llama »

abi wrote: Wed Jan 09, 2019 6:42 am X264 encode camera mode doesn't work in ZM under FreeBSD. All commands succeed, but resulting mp4 containers are empty (they have correct header, but no track). I can't solve this without ZM devs as the issue is definitely in C code. This is not a regression, X264 encode was broken from the beginning.
If they wish to lend me a hand, I can setup test box. I think, fix will be easy, the problem is to find whats wrong.
Same issue here on FreeBSD 11.2. I've been having separate problems with capture crashing when the Video Writer is set as H264 Camera Passthrough (viewtopic.php?f=38&t=27910) -- when the Video Writer is set as X264 Encode, capture appears to work but empty H264 files are produced. Live streams are visible and events have visible thumbnails but the event videos themselves are empty.
User avatar
iconnor
Posts: 2880
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: no valid mp4s created

Post by iconnor »

@abi my freebsd install is out of date. I don't really have time to figure out how to get a dev install setup.

Can you give a quick howto (for an advanced user :) ). To go from base install to zm installed?

Then I will get to the bottom of it.
User avatar
llama
Posts: 9
Joined: Sat Jan 05, 2019 4:26 am

Re: no valid mp4s created

Post by llama »

iconnor wrote: Thu Feb 07, 2019 4:28 pm @abi my freebsd install is out of date. I don't really have time to figure out how to get a dev install setup.

Can you give a quick howto (for an advanced user :) ). To go from base install to zm installed?

Then I will get to the bottom of it.
This is how I set up ZM on FreeBSD 11.2. Install ZM and the install its dependencies (PHP, webserver, database):

Code: Select all

pkg install -y zoneminder
pkg install -y php72-openssl mysql56-server nginx fcgiwrap 
The README of the ZoneMinder port (https://svnweb.freebsd.org/ports/head/m ... iew=markup) gives the subsequent OS-specific setup commands and configuration (eg database, Nginx, PHP etc) and gets printed out when the pkg is installed. The commands are in script form here: https://github.com/freenas/iocage-plugin-zoneminder/ (whilst a FreeNAS "plugin", it's just FreeBSD).

In short, to finish the install, run the commands in the script https://github.com/freenas/iocage-plugi ... install.sh and put the files from https://github.com/freenas/iocage-plugi ... /local/etc into /usr/local/etc on your machine.

Start/restart nginx, mysql-server, php-fpm, fcgiwrap and zoneminder and that should do it.
abi
Posts: 61
Joined: Fri Oct 23, 2015 11:25 am

Re: no valid mp4s created

Post by abi »

iconnor wrote: Thu Feb 07, 2019 4:28 pm @abi my freebsd install is out of date. I don't really have time to figure out how to get a dev install setup.

Can you give a quick howto (for an advanced user :) ). To go from base install to zm installed?

Then I will get to the bottom of it.
Hello, @iconnor.
Thanks you wish to pick this up!

I think my readme is still good. At least, I installed ZM quite fast using it. https://svnweb.freebsd.org/ports/head/m ... iew=markup
I believe, the only gotcha is to switch repo.

Create /usr/local/etc/pkg/repos/FreeBSD.conf and put there

Code: Select all

FreeBSD: {
  url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest"
}
pkg update / pkg upgrade will use latest repo after that.

If you want to compile ZM from source and save some time:
1. Install ZM from package (see above).
2. Deinstall ZM, keeping it dependenies (pkg delete zoneminder)
3. portsnap fetch extract
4. cd /usr/ports/multimedia/zoneminder
4.1. make will compile ZM for your
4.2. make extract will extract original source only
4.3. make patch is 4.2 and apply local port patches
4.4. make clean will clean steps above.

So, you can 4.3, add your patches manually and proceed with make or make install

Hope this helps
User avatar
iconnor
Posts: 2880
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: no valid mp4s created

Post by iconnor »

I have successfully setup a dev env for 1.33.1 on freebsd11.

so progress is being made
User avatar
iconnor
Posts: 2880
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: no valid mp4s created

Post by iconnor »

So it appears to actually NOT write out any frames, even though it says it is. wonderful.
abi
Posts: 61
Joined: Fri Oct 23, 2015 11:25 am

Re: no valid mp4s created

Post by abi »

I was thrilled as well when I've seen this :P And all calls reported SUCCESS.
Post Reply