Skip to content

Taking automated screenshots from a live video camera

November 23, 2008

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.

3 Comments
  1. otkar permalink

    For a video you can do the following to take a snapshot every 5 seconds:
    mplayer -vo png -vf screenshot -sstep 5 video.avi
    You should be able to do the same with your tv-tuner.

Trackbacks & Pingbacks

  1. Baby movements during sleep - epot's blog
  2. JPG van composite-in - 9lives

Comments are closed.

%d bloggers like this: