New FreeBSD port for 1.22.3.

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
freebsd-guy
Posts: 10
Joined: Sun Jan 14, 2007 11:06 pm

New FreeBSD port for 1.22.3.

Post by freebsd-guy »

Primary: http://catsspat.dyndns.org:2080/zoneminder/
Secondary: http://csua.berkeley.edu/~ricky/zoneminder/
Tertiary (direct links to tgz files):
http://www.o6.lv/files/zoneminder-freeb ... 22.3p3.tgz
http://www.o6.lv/files/zoneminder-freeb ... 22.3p4.tgz
http://www.o6.lv/files/zoneminder-freeb ... 22.3p5.tgz

# version 3 is almost identical to version 2 except it uses PHP5 instead of PHP4.
# version 4 contains patch for zm_html_view_monitor.php and has a newly written README.
# version 5 contains patch for zm_mpeg.h to fix compile issues with more recent ffmpeg source.
# version 6 contains updates to Makefile (ffmpeg-devel->ffmpeg, mod_perl->mod_perl2) as suggested by "Jimmy" and also updates for bktr support by "achix."

It was pretty hairy but I got it to work.
I'm running it on FreeBSD 5.5 with network cameras only
(Axis 206). Just about everything works, including liveview
on linux-firefox.

I plan on upgrading to FreeBSD 6.1 at some point, so if it
doesn't work there, I'll come up with a different port, but
no promises.

Also, I've never made a FreeBSD port before, so I'm sure
I'm not doing it the best way. I'm more than happy enough
to have gotten it to work.

Straight from files/README.FreeBSD in the port:

* A version of mysql MUST be installed and running for
zoneminder to operate. Port-dependency is set up to
install mysql50 (5.0.x) automatically. If you want
to use a different version, feel free to change the
port's Makefile.

* I chose to use php4 and php4-extension, which also
installs apache 1.x.x. If you're using other
versions, good luck to you.

* If you're building on 64-bit machine, get rid of
files/patch-SharedMem.pm
It as a hack for the sizes as I'm using it under
32-bit version of FreeBSD. Of course, if you built
already, it's too late to remove the patch. Just look
at it. I'm sure you can figure out how to undo.

* If this is your first installation, you need to seed
the mysql database with basic information. You
probably want to do this after seeing it successfully
build. On mysql5, follow these steps:

shell> mysql -h localhost -u root -p

mysql> source work/ZoneMinder-1.22.3/db/zm_create.sql
mysql> grant select,insert,update,delete on zm.* to 'zm'@localhost identified by 'zm'; flush privileges;
mysql> quit

* Documents are installed in
/usr/local/share/doc/zoneminder

* If you want ZoneMinder to start automatically, you can
either come up with a real zm.sh and put it in
/usr/local/etc/rc.d/ (and tell me so I know how to do
it right), or just put '/usr/local/bin/zmpkg.pl start'
in /etc/rc.local. Actually, I've not tested that yet.
Update: ver 0.2 of the port has rudimentary zm.sh
It is supposed to take care of ZoneMinder's dependency
on mysql.

* Obviously, there is no support for Linux video input
drivers. In fact, I don't even know if the bktr input
works on this. I'm only using network cameras. At
the moment, they're Axis 206.

* Dependencies are a bit hairy and there are so many
files that go everywhere, so package list is probably
incomplete. That means, even after you remove the
port, there may be some left over files.

* You may need to increase kernel shared memory pages.
This is what I'm using and it seems to work. Put these
in your kernel build file and recompile the kernel.

options SHMMAXPGS=65536
options SHMMNI=384
options SHMSEG=256

* Oh and you'll want to update /usr/local/etc/zm.conf
before trying to start ZoneMinder the first time.
ZM_DB_HOST is most likely "localhost" For the rest,
they depend on how you set up mysql. I think
database name set up by zm_create.sql is "zm."

* Good luck! You're going to need it!
Last edited by freebsd-guy on Wed Oct 17, 2007 1:39 am, edited 2 times in total.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Thanks for the comprehensive document :D

It would probably be worth adding it to the distro specific pages in the Wiki so it's a bit easier to find.
Phil
freebsd-guy
Posts: 10
Joined: Sun Jan 14, 2007 11:06 pm

Post by freebsd-guy »

zoneminder wrote:Thanks for the comprehensive document :D

It would probably be worth adding it to the distro specific pages in the Wiki so it's a bit easier to find.
I will get to it, but probably after I move (which is why I started looking into ZoneMinder in the first place).

In the mean time, I've fixed up a lot of stuff in the port, and tested it on a scratch-install FreeBSD 6.2 Release system. I added proper startup script and updated to php5.

Some of the instructions have changed, too, so if anyone tried it and (probably) failed, it's time to try again. Speaking of which, I don't think anyone did try it. I've only seen one download from a BSD machine, and that was a NetBSD machine. :roll: Oh well. I learned a lot of new things about ports, mysql, and php, so it's all good.
freebsd-guy
Posts: 10
Joined: Sun Jan 14, 2007 11:06 pm

Post by freebsd-guy »

I don't know how to add new entry to wiki, so I'm going to just post something reasonably formatted here and hope somebody can transfer it over to wiki. Once it's in there, I'm sure I can edit it as needed.

== Origin ==

This port project started its life based on quadra's original port for
version 1.19.2. Brooktree (bktr) video input support code written by
quadra is virtually unchanged in this port other than some function
argument changes to match the latest ZoneMinder version (1.22.3).
Although this code compiles, I have not tested its functionality.
Currently, I only have two Axis 206 network cameras, which work fine,
but I have not tested the set up with any other camera
configurations.

I have tested this port on FreeBSD 5.5 (i386) as well as FreeBSD 6.2
(i386) without any problems.

== Preparation ==

* Download the port (zoneminder-freebsd-port-1.22.3p[version].tgz)
* Become root and 'cd' to /usr/ports/multimedia/
* Extract the port files. You know how to do 'tar zxf' right?

You should now have /usr/ports/multimedia/zoneminder/

Now, go to the directory and look at files/patch-SharedMem.pm

What this patch does is to hard-wire native size to 4 (32-bits).
On FreeBSD, Perl is configured with -Duse64bitint by default and the
method that is used by SharedMem.pm to determine architectural bit
width incorrectly considers an i386 machine as 64-bit capable. I'm
not a perl expert -- in fact, I hate perl -- and I really have no
idea how to properly determine pointer size in Perl, so this patch
exists. Obviously, if you are running FreeBSD-AMD64 (or Alpha or
something, although I have no idea if this software would work on
that architecture), you will want to get rid of this patch file.
Just delete it _before_ you make.

And if you're bored, feel free to go through all the patch files just
marvelling at all the trouble I had to go through ^_^;

Now that we've gotten that little quirk out of the way, we'll move on
to Makefile. Open Makefile using your favorite text editor and modify
the following items if they're not suitable for you.

* WEBBASE : This is where your web server will serve from. If you
already have apache installed, you should point this to the same
place where apache thinks is the web base. Default is
/usr/local/www, as can be seen in the Makefile.
* ZM_DB_HOST : This is where mysql server runs. If you're running
mysql server on a different machine, you'll want to update this
line, but I'm not sure if you can avoid installing mysql on this
machine. Disk space is cheap, so I don't think it's that big a deal
having mysql just sitting there, as long as it's not started.
* ZM_DB_NAME : This is the database name that ZoneMinder will use.
I'm pretty sure ZoneMinder won't mind sharing a base database with
other applications, but it certainly doesn't hurt to let it have its
own database space, so this defaults to "zm"
* ZM_DB_USER and ZM_DB_PASS are username and password for the
database.

We're almost ready to "make," but first, consider the following points
and just imagine how things can break based on your situation.

* If you do not have apache installed, this port will install version
1.xx.xx of apache. On the other hand, if you already have apache
2.xx.xx installed, I do not know what will happen. My guess is that
things will work just fine since php5 port will see apache2
installation and skip apache1 installation.
* If you have mysql version other than 5.0.xx installed, this port
build will probably fail. Even if it doesn't fail, you probably do
not want multiple versions of mysql installed on your machine. You
can either edit the dependency in the Makefile to point to your
version of mysql, or get rid of the dependency statement for mysql.
Getting rid of it is not as nice, but I'm sure you're able to keep
the dependencies in mind when messing around with ports in the
future.
* If you have PHP4 installed, you should modify the dependencies in
the Makefile to point to php4-extensions instead of
php5-extensions. I know for a fact that both versions work fine
with ZoneMinder.
* I have not set up dependencies for perl modules Device::SerialPort
and X10::ActiveHome because I do not have PTZ camera and my X10 is
handled by another dedicated machine. If you want this, you'll want
to tinker with the port some more. You can also manually install
those ports (if they exist) before doing make. I imagine
ZoneMinder's configure script will pick them up.

That's about it. Let's make!

== Making ==

There's really nothing special about making. Just 'make' will do.
However, during the dependency builds, make sure PHP install includes
the apache module. If you already have PHP installed without apache
module, you can always tinker with the Makefile in
/usr/ports/lang/php5/ and do 'make deinstall' followed by 'make
reinstall' to reinstall the port with additional modules.

If the build fails, take a deep breath, yell at your computer for
a moment, and try to figure out if you messed up anything while
changing the Makefile in one of the above steps. If you do not
believe you've done anything wrong and still can't figure out why
the build fails, there's always the forum....

If it builds fine, feel free to 'make install'

However, do NOT 'make clean' yet!

== Seeding the database ==

If this is the first time installing ZoneMinder, you'll need to see
the mysql database with ZoneMinder's configuration information. To do
this, follow these steps as a root user.

First, if this is the first time mysql was installed, you'll want to
consider where you want the database files to reside. Default is
/var/db/mysql/ but you may have set up a dedicated partition for it.
If you want to change it, just put the following line in /etc/rc.conf

* mysql_dbdir="/somewhere/else/you/want"

Obviously, you'll want this line in there, too:

* mysql_enable="YES"

Now, start the sucker up.

shell> /usr/local/etc/rc.d/mysql-server start

Assuming it started fine, give it a few seconds and then continue.
Note that you should be at /usr/ports/multimedia/zoneminder/ for the
following steps.

shell> mysql -h localhost -u root -p

This will ask for a password. Just press enter to go with an empty
password. You should now be in mysql command line interface.

mysql> source work/ZoneMinder-1.22.3/db/zm_create.sql

Above runs bunch of SQL commands from the file, seeding the
database.

mysql> grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass'; flush privileges;

Above sets up permissions. Note that if you changed database name,
user name, or password in the Makefile, you'll need to modify above
command accordingly.

mysql> quit

That one should be obvious to you.

== Post-Installation Quirks ==

PHP5 installation does not necessarily set up the apache configuration
file properly. You will want to make sure that following lines are in
apache configuration file, /usr/local/etc/apache/httpd.conf

* AddType application/x-httpd-php .php
* AddType application/x-httpd-php-source .phps

While you're at it, you might also want to check that following line
is in the configuration file.

* LoadModule php5_module libexec/apache/libphp5.so

== Automatic Execution at Boot ==

Obviously, if this is to be used as a security device, you'll want it
to start automatically on a reboot. Again obviously, you need to have
both apache and mysql start up as well, unless of course, you're
running mysql on a remote machine. If you are, I'm sure you're an
expert at this stuff already.

Add following lines into /etc/rc.conf, if not already present. Order
is not important.

* apache_enable="YES"
* mysql_enable="YES"
* zm_enable="YES"

Just for your information, I had to put 'sleep 10' in ZoneMinder
startup script because mysql port does not become available
immediately after mysql startup script finishes.

== More Quirks ==

Depending on the number of cameras and their resolution settings, you
may need a lot more shared memory than provided by a default kernel.
If you've never built a custom kernel before, umm, time for you to
read the FreeBSD Handbook. It can be found at
/usr/share/doc/handbook/index.html or at http://freebsd.org/

For the rest of you, just add a reasonable-looking version of the
following lines into your kernel configuration file and go though the
buildkernel, installkernel process.

* options SHMMAXPGS=65536
* options SHMMNI=384
* options SHMSEG=256

I think above gives maximum of 256MB of shared memory. SHMMNI
statement probably isn't required since ZoneMinder probably creates
one big instance per camera instead of many little instances. I'm not
sure about the last one. Whatever the case, above works for me with
two Axis 206 cameras.

Adding the following line into /etc/sysctl.conf may speed up the
shared memory accesses, so even though it's not required, it's
probably a good idea.

* kern.ipc.shm_use_phys=1

That's all folks!

== Other Pointless Rant ==

FreeBSD is awesome! I used to be a Linux guy back in the days, but
once I discovered FreeBSD (make world, ports, boot-up process, slices
and partitions, GBDE, etc.), I never looked back! Actually, I did try
out Gentoo a couple of years ago. I wasn't particularly impressed.
But to each his/her own.

Be paranoid out there.
Fordy
Posts: 1
Joined: Tue Apr 24, 2007 6:34 am
Location: Winchester, UK

Hrrmmm..

Post by Fordy »

Heya Chaps,

Been following this useful procedure - this line appears wrong;

mysql> source work/ZoneMinder-1.22.3/db/zm_create.sql

It needs to have a .in on the end, but that worked :)

How come you haven't submitted this port int he freebsd ports archive? :)

I run into compile problems on freebsd 5.4-RELEASE :(

Somewhere around ffmpeg - currently trying to sort this mess out - for info:

===> Building for zoneminder-1.22.3,1
/bin/cp /usr/home/forda/zoneminder/zoneminder/files/videodev.h /usr/home/forda/zoneminder/zoneminder/work/ZoneMinder-1.22.3/src
/bin/cp /usr/home/forda/zoneminder/zoneminder/files/zm_fbsd_camera.cpp /usr/home/forda/zoneminder/zoneminder/work/ZoneMinder-1.22.3/src
/bin/cp /usr/home/forda/zoneminder/zoneminder/files/zm_fbsd_camera.h /usr/home/forda/zoneminder/zoneminder/work/ZoneMinder-1.22.3/src
make all-recursive
Making all in src
if c++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/local/include/mysql -I/usr/local/include -I/usr/local/include -I/usr/local/include/ -MT zmc.o -MD -MP -MF ".deps/zmc.Tpo" -c -o zmc.o zmc.cpp; then mv -f ".deps/zmc.Tpo" ".deps/zmc.Po"; else rm -f ".deps/zmc.Tpo"; exit 1; fi
In file included from jinclude.h:20,
from zm_jpeg.h:22,
from zm_image.h:33,
from zm_monitor.h:28,
from zmc.cpp:27:
/usr/local/include/jconfig.h:12:1: warning: "HAVE_STDLIB_H" redefined
In file included from zm_config.h:20,
from zm.h:28,
from zmc.cpp:24:
../config.h:71:1: warning: this is the location of the previous definition
if c++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/local/include/mysql -I/usr/local/include -I/usr/local/include -I/usr/local/include/ -MT zm_event.o -MD -MP -MF ".deps/zm_event.Tpo" -c -o zm_event.o zm_event.cpp; then mv -f ".deps/zm_event.Tpo" ".deps/zm_event.Po"; else rm -f ".deps/zm_event.Tpo"; exit 1; fi
In file included from /usr/local/include/ffmpeg/avformat.h:36,
from zm_mpeg.h:27,
from zm_event.cpp:30:
/usr/local/include/ffmpeg/avcodec.h:2450: warning: `ImgReSampleContext' is deprecated (declared at /usr/local/include/ffmpeg/avcodec.h:2447)
/usr/local/include/ffmpeg/avcodec.h:2457: warning: `ImgReSampleContext' is deprecated (declared at /usr/local/include/ffmpeg/avcodec.h:2447)
/usr/local/include/ffmpeg/avcodec.h:2461: warning: `ImgReSampleContext' is deprecated (declared at /usr/local/include/ffmpeg/avcodec.h:2447)
/usr/local/include/ffmpeg/avcodec.h:2463: warning: `ImgReSampleContext' is deprecated (declared at /usr/local/include/ffmpeg/avcodec.h:2447)
In file included from zm_mpeg.h:27,
from zm_event.cpp:30:
/usr/local/include/ffmpeg/avformat.h: In function `void av_init_packet(AVPacket*)':
/usr/local/include/ffmpeg/avformat.h:66: error: integer constant is too large for "long" type
/usr/local/include/ffmpeg/avformat.h:66: error: `INT64_C' undeclared (first use this function)
/usr/local/include/ffmpeg/avformat.h:66: error: (Each undeclared identifier is reported only once for each function it appears in.)
/usr/local/include/ffmpeg/avformat.h:67: error: integer constant is too large for "long" type
/usr/local/include/ffmpeg/avformat.h: At global scope:
/usr/local/include/ffmpeg/avformat.h:284: warning: `AVFrac' is deprecated (declared at /usr/local/include/ffmpeg/avformat.h:118)
In file included from jinclude.h:20,
from zm_jpeg.h:22,
from zm_image.h:33,
from zm_event.h:35,
from zm_event.cpp:31:
/usr/local/include/jconfig.h:12:1: warning: "HAVE_STDLIB_H" redefined
In file included from zm_config.h:20,
from zm.h:28,
from zm_event.cpp:28:
../config.h:71:1: warning: this is the location of the previous definition
*** Error code 1

Stop in /usr/home/forda/zoneminder/zoneminder/work/ZoneMinder-1.22.3/src.
*** Error code 1

Stop in /usr/home/forda/zoneminder/zoneminder/work/ZoneMinder-1.22.3.
*** Error code 1

Stop in /usr/home/forda/zoneminder/zoneminder/work/ZoneMinder-1.22.3.
*** Error code 1

Stop in /usr/home/forda/zoneminder/zoneminder.
[/b]
freebsd-guy
Posts: 10
Joined: Sun Jan 14, 2007 11:06 pm

Re: Hrrmmm..

Post by freebsd-guy »

Fordy wrote: Been following this useful procedure - this line appears wrong;

mysql> source work/ZoneMinder-1.22.3/db/zm_create.sql

It needs to have a .in on the end, but that worked :)
It is not wrong. Making of ZoneMinder should have created zm_create.sql
based on zm_create.sql.in. If you don't see the file, either make failed, or
the build area was cleaned after make.
How come you haven't submitted this port int he freebsd ports archive? :)
Because I don't believe the work I did is complete. Dependencies aren't
handled all that elegantly. For example, it would be nice to give the user
option of using different version of PHP, Apache, and MySql. This was my
first ever port attempt so I was pretty happy to get it to this point. It
certainly would be nice to have an official FreeBSD port in the archive,
though. Maybe I'm just being a chicken.
I run into compile problems on freebsd 5.4-RELEASE :(
Update: After a short googling session, I found the answer within the
ZoneMinder forums. Latest ffmpeg changes was causing the failure.

I've added version5 of the port at my site with an additional patch file
to deal with this. With it, I've successfully compiled it on 5.5REL_ENG.

--rich
john.a.sutherland
Posts: 15
Joined: Fri Jun 01, 2007 6:47 pm

ffmpeg on Fedora 7 problems

Post by john.a.sutherland »

When I try to make ZM, here is the error I get:

/usr/include/ffmpeg/avformat.h:66: error: 'INT64_C' was not declared in this scope

Will a patch to ZM 1.22.3 fix this? What patch? Where?

Thanks,

John
freebsd-guy
Posts: 10
Joined: Sun Jan 14, 2007 11:06 pm

Post by freebsd-guy »

Ahh, crap! I had my links wrong. People who downloaded p5 version actually ended up downloading p4 version instead. Stupid stupid mistake. I just fixed the link (2007-06-05 10:35am PDT). Please try again with the latest port.

--rich
Sn3ak
Posts: 1
Joined: Sat Jul 14, 2007 7:19 am

Post by Sn3ak »

Great work.

I am going to see about making a few changes to your port, which I hope to submit back here shortly. I was able to test the port with a bktr device, which seems to work well.

The only question / problem I have, is that the load seems to be considerably higher then the same setup on a Linux system. Difference being about 3% load on the Linux box, and anywhere from 39% - 99% on the BSD box.

I don't have an IP camera to test with, out of curiosity what's the load look like on your setup?
freebsd-guy
Posts: 10
Joined: Sun Jan 14, 2007 11:06 pm

Post by freebsd-guy »

Sn3ak wrote:Great work.

I am going to see about making a few changes to your port, which I hope to submit back here shortly. I was able to test the port with a bktr device, which seems to work well.

The only question / problem I have, is that the load seems to be considerably higher than the same setup on a Linux system. Difference being about 3% load on the Linux box, and anywhere from 39% - 99% on the BSD box.

I don't have an IP camera to test with, out of curiosity what's the load look like on your setup?
Wow, I didn't even think about the load. I just assumed it takes a lot of compute to process video. But then my load doesn't fluctuate like yours, so maybe it's bktr input method that causes the difference. I don't know if this helps since I don't have a Linux box to compare with, but here are my load state:

Code: Select all

Cam Res     Mon/Alm Active Zone(s)     Method/Sense  zma/zmc Load %
--- ------- ------- ------------------ ------------- --------------
1   640x480 3/7 fps 1 zone  64%        Blobs   /High 15/12
2   640x480 2/5 fps 2 zones 22-7 (15%) AlrmdPxl/Med   9/ 7
With other system requirements (interrupts, etc.), everything eats up around 47% of the total CPU time. I'm not sure about the load when it alarms, but I assume it's way up there, near or at 100%.

This is on an AMD Turion64 machine with 1MB L2 running pegged at the _minimum_ P-state (800MHz DDR333 0.9V) in 32-bit mode.

Image settings are 24-bit color and JPEG quality at 70. I'm going for resolution over fps.

Does that seem unreasonable? At least it's stable. She's been up for 39 days without an issue.

--rich
[/code]
Jimmy
Posts: 16
Joined: Wed Jun 23, 2004 9:39 pm

Post by Jimmy »

Excellent work, I'm going to have to attempt to set this up on 6.2 just looking for some suitable IP Cameras to use it with!
achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

LMLBT4M on FreeBSD 6.2

Post by achix »

Hi i'd like to know if anyone managed to successfully run ZM with the above card (LMLBT4M, its from linux media labs) and FreeBSD 6.2-RELEASE.
From xawtv i can see the card working, however from zm no luck.

I define the camera, but i only see a blue image.

i'd like to ask Sn3ak, how did he manage to have ZM working with bktr cards.

Any hints?
Jimmy
Posts: 16
Joined: Wed Jun 23, 2004 9:39 pm

Post by Jimmy »

Managed to get zoneminder installed, a few notes for the uninitiated on 6.2:

* The Makefile points to multimedia/ffmpeg-devel this has now been renamed to multimedia/ffmpeg and the Makefile needs to be modified accordingly.

* ffmpeg (09/2007) depends on a recent release of Xvid v1.1.3 I believe so make sure you update your xvid install first.

* The Makefile points to www/mod_perl however this is now deprecated in favour of www/mod_perl2 the makefile needs to be updated accordingly.

* You may require to symbolically link libz.so to libz.so.2 as required for the build, simply run: ln -s /usr/lib/libz.so /usr/lib/libz.so.2

Everything worked as expected apart from that, have managed to set it up with a Kodicom KMC-4400R, which uses the bktr driver, and appears to be working by mapping the camera source to /dev/bktr however I'm waiting on my cameras turning up so I cant vouch this is working, although in the viewing window I am presented with a black screen, timestamped and dated and it reads 40fps beneath.

My only concern is on a Duron 1GHz system, the processor usage is now 95% and I've not even set up recording yet -- worrying as I had this same system running on slackware and it wasn't anywhere near that!
achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

Post by achix »

Once i managed to get *smth* out of the /dev/bktr0 CPU usage went almost 75+% Idle.
All that in a Pentium III(451.92-MHz 686-class CPU) with 382 MB.

My problem is that i get smth like
Image
:roll:
achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

Post by achix »

Post Reply