Tag: Linux

Taking automated screenshots from a live video camera

Following my previous post, I attached a video camera to the composite input of my tv tuner. One good thing I didn’t noticed yesterday is that mplayer can be told to directly use pvr:// as a source instead of the generic tv:// (with many options). So you just have to enter mplayer pvr:// -tv device=/dev/video1:input=0 in order to watch tv.

Noticed the input=0 above? This tells the tuner to take the video signal from the tv (read the mplayer man page to see how to change the channel). Now, since I connected my video camera to the composite video in, I need to tell mplayer to use it with input=1. One last thing: taking a screenshot in mplayer is done by pressing the ‘s’ key (with option -vf screenshot. In summary, the image below was taken with mplayer pvr:// -tv device=/dev/video1:input=1:noaudio -vo x11 -vf screenshot
(camera facing the screen).

blurry capture of computer screen taken by camera connected to tv tuner

Now I want to take one screenshot every 5 seconds, even when I’m not there to press the ‘s’ key! For this purpose, we need to use a fifo file and mplayer in slave mode. Mplayer in slave mode will listen to commands we automatically send into the fifo file (by a different process, see below). This is how we do this:

mkfifo myfifofile.tmp
mplayer -slave -input file=myfifofile.tmp pvr:// -tv device=/dev/video1:input=1:noaudio -vo x11 -vf screenshot

And from another console, we can type echo "screenshot 0" >> myfifofile.tmp to take the screenshot. To automate all this, the following simple bash code is sufficient:

#!/bin/bash
# will send mplayer screenshot command every 5 seconds to fifo file
# stop this with Ctrl + C
LIMIT=0
while [ $LIMIT -lt 1 ]; do
echo "screenshot 0" >> myfifofile.tmp
sleep 5
done

In the end, stop the bash script with Ctrl + C and quit mplayer with echo "quit" >> myfifofile.tmp.

A first step toward TV on my Linux laptop

I recently got a Hauppauge WinTV-PVR-USB2 (a TV tuner, video recorder and FM receiver) because I read it was well supported on GNU/Linux. The following post explains how I installed it on a Fedora Core 9. If you want to install it with another Linux distribution, some information may vary but most of the following steps will be exactly the same.

First connect the USB device, the list of USB devices shows my system has recognised it:

[root@localhost ~]# lsusb
Bus 002 Device 003: ID 2040:2900 Hauppauge
...
[root@localhost ~]# dmesg
usbcore: registered new interface driver pvrusb2
pvrusb2: Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner : V4L in-tree version
pvrusb2: Debug mask is 31 (0x1f)
firmware: requesting v4l-pvrusb2-29xxx-01.fw
pvrusb2: ***WARNING*** Device fx2 controller firmware seems to be missing.
pvrusb2: Did you install the pvrusb2 firmware files in their proper location?
pvrusb2: request_firmware unable to locate fx2 controller file v4l-pvrusb2-29xxx-01.fw
pvrusb2: Failure uploading firmware1
pvrusb2: Device initialization was not successful.
pvrusb2: Giving up since device microcontroller firmware appears to be missing.

Although my tuner is fully recognised, the system needs a firmware in order to make it work. Where is the firmware? A quick search on a well-known search engine redirects us to Mike Isely’s website where he explains how to get the driver (Mike actually also wrote the driver for this TV tuner). Although I got the CD with drivers for Windows, I prefer to use the latest driver that can be found on the Hauppage support website. Mike also writes you can get the driver from the ivtv project.

So I uncompress the driver in the “win_driver” directory and launch Mike Isely’s fwextract.pl script:

[jepoirrier@localhost hauppauge]$ mkdir win_driver
[jepoirrier@localhost hauppauge]$ unzip hauppauge_cd_3.4d1.zip -d win_driver/
[jepoirrier@localhost hauppauge]$ ./fwextract.pl

The script extracted 4 drivers (2 decoders and 2 encoders) and dmesg already told me the two I need: v4l-pvrusb2-29xxx-01.fw and v4l-cx2341x-enc.fw (as encoder). To know where to put these files, check a little bit on the web (this depends on your GNU/Linux distribution). On the Fedora Core 9, it’s in /lib/firmware, so:

[root@localhost hauppauge]# cp v4l-cx2341x-enc.fw /lib/firmware
[root@localhost hauppauge]# cp v4l-pvrusb2-29xxx-01.fw /lib/firmware

Unplug your USB cable, re-plug it and a dmesg should give you a long list of what your system detected, the most interesting part being the last line where it request the firmware and doesn’t stop: firmware: requesting v4l-cx2341x-enc.fw 🙂 Now check your video devices and you should have an additional /dev/videox:

[root@localhost hauppauge]# ls /dev/vid*
/dev/video /dev/video0 /dev/video1

In my case, /dev/video1 is the one I need …

Now, how to watch TV? TVTIME seems to be good but, unfortunately, my video card driver doesn’t support hardware YUY2 overlay (I have an ATI Radeon Mobility HD 2600 with the open source radeon driver). No problem: mplayer /dev/video1 shows a very beautiful snow. Now I need an antenna or a cable to connect to my tuner …

mplayer -vo x11 /dev/video1 -vf and then s

Pixel lapse under Linux

pixel-lapse under Linux

Finally, I got a working pixel lapse software under Linux 🙂 It’s a bit late (and I have to work tomorrow), code is rather dirty but I’ll publish it as soon as possible (btw that’s why I needed a webcam and a library to read it yesterday). Originally,

"pixel lapse" photography is the process of creating an image one pixel at a time. Beginning in the upper left corner, pixels are captured sequentially at a set rate until the entire image is formed.

Unfortunately, their software only runs on MacOS and Windows and requires Quicktime. Here, I "only" use OpenCV which is free and available under all the OS mentioned in this post. More details soon …

The “full-size” (640×480) image is here on Flickr

Edit on November 5th, 2008: version 0.1 of the software is available here.

Watch your webcam with mplayer

A small post just to keep this command at hand:
mplayer -fps 30 -tv driver=v4l:width=640:height=480:device=/dev/video1 tv://
This allows you to watch what your webcam “sees” (provided it uses a video4linux webcam). Btw, Cheese is funny to use too!

I was also trying to find a decent Python library for video4linux but I only found outdated ones (libfg, 2003, and pyv4l, 2002). I guess I’ll have to use some C library for a small project I’ll tell you about later 😉

Old house for geeks in Liege (Belgium)

My parents-in-law just came for some holidays in Belgium and they choose a nice, old-style house near Liège (Belgium), in Trooz. It’s called “Biche les prés“. It has plenty of rooms, a nice, well-kept garden, it’s clean and situated near a forest, away from the city (20 km from Liège) … and it has a computer with GNU/Linux (RedHat 9 in dual boot with MS-Windows) and an internet connection (modem). Of course, M. Spirlet won’t give you the root password 😉 but, at least, if you left your laptop at work (like I did), you can read your mail with your favorite operating system.