Showing posts with label webcam. Show all posts
Showing posts with label webcam. Show all posts

15 May 2014

577. Skype and webcam on debian wheezy: black screen

This is another shameless re-posting of a solution published by others. See e.g.

Why am I doing this? Mostly because this blog doubles as a notebook where I can write down solutions that worked for me so that I don't find myself scouring the internet over and over again for the same solution.

I hope that I'm adding a bit of value by providing step-by-step solutions and snazzy screenshots though.

The issue:
even though the camera is working fine there's only a completely black picture in skype (not underexposed -- just plain black):

The solution:
Use LD_PRELOAD to load the 32 bit V4L library (which you need to have installed -- use apt-file to find out what package). You can either start skype from the command line, or make changes to the launcher, either via main menu  as shown in the screenshot or by editing ~/.local/share/applications/skype.desktop i.e. run skype with 
env LD_PRELOAD="/usr/lib/i386-linux-gnu/libv4l/" skype

 At this point starting skype + webcam should be a happy marriage:
(aside from exposure, white balance etc. etc.)

11 November 2012

278. Monitoring your office with a webcam and zoneminder on debian

Update: so this worked fine with my thinkpad sl410 camera, but I'm having a lot of trouble getting an image off of my usb Pixio cam (Z-Star Microelectronics Corp. USB 1.1 Webcam) with "Got signal 11 (Segmentation fault), crashing" and "'zmc -d /dev/video0' exited abnormally, exit status 11". Zoneminder feels annoyingly temperamental at times. Anyway, I ended up hacking together a poor but functional solution by using a shell script and streamer to save stills every few seconds, then letting zoneminder analyse and capture. Setting up two Airlink 101 AIC250W was remarkably easy though (although I remember having a lot of trouble in the past). I've also experimented with motion,  and although I'm having issues with the image colours it's working very well.

Original post
While I figured that the head of school might have a universal key allowing access to all the offices in the department (the cleaners do), finding out that he had used it to open my office for a trivial purpose has ticked me off.

While you may not have an expectation of privacy at your company office, I certainly do when it comes to my department office.

So I'm not too happy about that, and while monitoring my office will not prevent future breaches of privacy, it will at least ease some of the paranoia if it turns out that my office doesn't routinely get entered.

This post only deals with a locally attached webcam -- I struggled with remote wifi-connected webcams a few years ago with little luck.
sudo apt-get install zoneminder
sudo apt-get install v4l-conf v4l2ucp
sudo cp /etc/zm/apache.conf /etc/apache2/sites-enabled/zm.conf
sudo service apache2 restart

Figure out what video devices you have:
ls /dev/video* 
and make sure www-data can access them
sudo adduser www-data video

You can now navigate to http://localhost/zm
Click on 'add monitor'

These settings are fine.

Note: these settings did NOT work. Keep reading the post...

Setting up the camera seemed deceptively easy -- everything went fine, except actually getting an image.

note the red colour for the video device. No good.

Looking at the log I was getting
Failed to set video format: Invalid argument
'zmc -d /dev/video0' exited abnormally, exit status 255

which is when I googled and found this post:

Basically, getting the settings absolutely right matters!

which told me
video capture
 index                   : 0
 type                    : VIDEO_CAPTURE
 flags                   : 0
 description             : "YUV 4:2:2 (YUYV)"
 pixelformat             : 0x56595559 [YUYV]
 index                   : 1
 type                    : VIDEO_CAPTURE
 flags                   : 1
 description             : "MJPEG"
 pixelformat             : 0x47504a4d [MJPG]
 type                    : VIDEO_CAPTURE
 fmt.pix.width           : 1600
 fmt.pix.height          : 1200
 fmt.pix.pixelformat     : 0x47504a4d [MJPG]
 fmt.pix.field           : NONE
 fmt.pix.bytesperline    : 0
 fmt.pix.sizeimage       : 5760000
 fmt.pix.colorspace      : unknown
 fmt.pix.priv            : 0

so changed my settings to
It took a bit of trial and error

Next, I was receiving
Got unexpected memory map file size 49153524, expected 230401524
and this post helped me:

Our old friend shmmax eh? Apparently I had about 32 mb set up (!) on my laptop, so I changed it to 671088640 (640 mb)

sudo sysctl -w kernel.shmmax=671088640

See this post for how to make it permanent.

Anyway, once all is well you will hopefully see something like this (note the colours -- the /dev/ is a nice orange, although the log is still an unhappy red)
Now we can actually do things. Click on the name of your device (here: laptop) and you should get something like

You can now click on Zones in the main menu and add one (takes a little bit of trial and error, but you'll get there). To get motion detection, and thus get ZM to save things, change the mode from Monitor to e.g. modec

Your files will  be found under /usr/share/zoneminder/events but you can change that using the setting menu which you can access in the top right corner in the main window.

So that's pretty much it. There are a couple of settings you might want to fiddle with:
You might want to set up ffmpeg to allow for generation of video fles

So I got fed up with one of my cameras not working together with zoneminder. As a temporary fix I set zoneminder to use 'file' instead of 'local' or 'remote'. So now zoneminder looks at ~/webcam/current.jpg.
In that directory, a script is running (you need to install streamer):

while true
do streamer -c /dev/video0 -b 24 -s 640x480 -o current.jpeg -q 2> /dev/null
        sleep 1

Also, I created a directory and symmlinked it to /usr/share/events to prevent my root partition from filling up:
mkdir zm/
chown www-data zm/
sudo rm /usr/share/zoneminder/events -rf
sudo ln -s /home/me/webcam/zm /usr/share/zoneminder/events