Skip to content


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.

Possibly related posts: (automatically generated)

  1. A first step toward TV on my Linux laptop
  2. Watch your webcam with mplayer
  3. Beginning with an IR camera
  4. Mplayer install for FC3
  5. Automated Pubmed reference to BibTeX

Posted in Open Source, User Interface.

Tagged with , , , , , , , .


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. otkar says

    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.

Continuing the Discussion

  1. Baby movements during sleep - epot's blog linked to this post on January 28, 2009

    [...] a while, here is why I got a TV tuner for my Linux laptop, took screen captures and wrote a script to add a timestamp on pictures … I wanted to know how my (then [...]

  2. JPG van composite-in - 9lives linked to this post on February 9, 2009

    [...] Taking automated screenshots from a live video camera – epot's blog lees dan eens door, maakt gebruik van mplayer… [...]