Tag: mplayer

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.

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 😉