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

Happy Diwali 2008 in Belgium!

Diwali by Kalyan Kumar on FlickrDiwali, the Indian Festival of Lights, is under way in India. But if you live in Belgium, there will be at least three occasions to celebrate!

In Antwerpen, first, on October 29th, morning.

Then in Leuven, on November 1st evening, organised by the association of Indian students in Leuven.

Finally in Ghent, on November 3rd evening, organised by the Indo-Belgian Association of Ghent.

Edit on November 1st: Bharatiya Samaj is also organising Diwali in Bruxelles on November 8th.

By the way, Rose, a non-profit organisation supporting and fostering basic education for children in developing countries will organise its traditional Fund raising Indian Dinner on November 29th, 2008, in Leuven.

Photo credit: “happy diwali!” by Kalyan Kumar on Flickr (CC-by-sa)

Belgian police is storing personal details in a database

If you live in Belgium, you probably noticed a small buzz about a database police is building about Belgian citizens and, more precisely, about the access control of this database. The “problem” is that this database already exists and it has a legal basis since … 1998 (10 years!). But mainstream media won’t tell you that (or I’m unaware of it). I don’t think there is a conspiracy. It’s just that, sadly, the current economic environment doesn’t leave much space for this kind of information. The Minister of Justice’s website has more info on this database and its content (excerpt of translation below):

The database already appeared a royal decree. This decree states that the police can store a bunch of sensitive data about certain categories of Belgian citizens since they are 14-years-old.
These include information on about family ties, consumption habits, ethnicity, physical and mental health, political and religious beliefs, membership of trade unions and political parties and suspicions of criminal offenses.

So what can we do about it? Human rights organisations as well as members of the Parliament (La Chambre, look for “P0499”) questioned the Minister of Justice, Jo Vandeurzen. He agreed that there should be both internal and external controls on what is inserted, who have access to the data, who can check the data and the access, … He promised the “Committee P“, the privacy committee and a supervisory body headed by a magistrate will be consulted. Let’s see …

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 😉

JoVE and (self-)archiving?

In my previous post, I was glad to see that the Journal of Visualized Experiments (JoVE) was now indexed by PubMed. I then spent some time watching some very interesting videos. And I realized that something is missing …

In my mind, I thought that third-party archiving (like arXiv or self-archiving) was one of the mandatory requirements for Open Access journals … and I was wrong. It seems JoVE is not giving the (technical) possibility to download the publication from their website (all what you can download is the abstract in text version). Now that this publication is a video and not a text/PDF version, it’s a problem for me (who cares?) and the Open Access movement (imho).

“Classical” Open Access journals are “just” an evolution of traditional, Closed Access journals (or rather a return to the original transmission form of scientific papers): usually, you can read the paper on the journal website but you can also download it and print it if you want (for offline reading or if you still prefer articles on paper). The problem with videos is that you can’t print them. Is it a sufficient reason to forbid the download of these videos?

Fortunately, there is a technical trick to allow you to download the video (it will still be in Flash 9 format but this problem is currently out of our scope). Once you are on the page of the interesting video (example), view its source code (Ctrl+U in Firefox) and look for the string “xml_file_name”. You can now copy the value of this variable and you can stop before the first “%26” you encounter ; for our example, we’ll copy this: “http://www.jove.com/projects/VideoChapterXML/default.aspx?VideoID=211”. Enter this in your address bar and you’ll get another (XML) file (hence the name). Now on the first line, you’ll get the URL of your video in Flash format (flv); in our example: “http://source.jove.com/164.flv”.

In the future I wonder if JoVE will include a link to download its videos or it will obfuscate its source code in order to forbid further download.

JoVE on PubMed

JoVE, the Journal of Visualized Experiments is a peer reviewed, open access, online journal devoted to the publication of biological research in a video format. Think of a YouTube-like service for the life-science community, add a quality control before publication and you’ll get the picture. As many other Open Access scientific journal, JoVE is now indexed in PubMed, the life-science publications directory. It’s nice to see interesting, open and innovative initiatives getting a “recognition” like this.

Thanks to Biosingularity for the info.

E-conferences

Following my previous post about an e-conference, Daneel Ariantho provided me with interesting informations …

The conference about scientific patents was part of Second Nature, (scientific journal) Nature’s home in the virtual world of Second Life. Following their description, Second Nature is home to scientific exhibitions, ongoing projects and regular events. The conference in itself was given in November 2007 but, unfortunately, nor slides nor podcast are available. In real life, if you miss a conference, you still have a copy of the slides or, at least, the abstract 😉 .

In the second part of my post, I was wondering if contacts were better in virtual worlds and if the quality standard of most “real world” scientific events was still there. But since this particular event was organized by a Closed Access journal on a semi-closed virtual world, I will wait for more events of this kind before forming an opinion on these events (current educational events in Second Life doesn’t seem to be too serious …).

E-conference about scientific patents

Conference about scientific patents

While looking for pictures related to patents, I found these interesting ones taken by Daneel Ariantho on Flickr. They depict a virtual conference about scientific patents. It could be interesting to get more information about 1) the content of this conference and 2) the kind of conferences organized in these virtual worlds. It could also be interesting to see the social aspects of these conferences (are your contact better/different in a virtual conference?) and the “quality control” (of speakers, of posters, of advertizers, …).