I can't believe how hard it is to find a simple digital webcam snapshot program. Here is one. :-) It is a Tk frontend to mplayer, run in slave mode.
screenshot Remember, for best results, look at the camera. :-)
#!/usr/bin/perl -w
use strict;
use Tk;
use Proc::Killfam;
use Tk::Spinbox;
$|++;
# by zentara of perlmonks, July 18, 2011
# this is free to use and distribute
# I wrote this because I wanted just a simple
# webcam grab for my built-in digital camera
# each snap shot will be deposited in the pwd as shot0001.png, shot000
+2.png, etc
# you can run mplayer by itself to do the same thing,
# but remembering all the key options and commandline stuff
# is a mind blower :-)
#put your preferred settings here
#my($width,$height) = (640,480);
my($width,$height) = (800,600);
# defaults are normally good
my $device = '/dev/video0';
my $brightness = 0; # range -100 to 100
my $contrast = 0;
my $fps = 30; #default frames per second
my $snaps_taken = 0; #counts number of snapshots taken
$SIG{INT} = sub { &close_it_up };
$SIG{PIPE} = 'IGNORE';
my $mw = MainWindow->new(-background =>'black');
$mw->Tk::bind("<q>", sub{&close_it_up});
$mw->Tk::bind("<Escape>", sub{&close_it_up});
$mw->protocol('WM_DELETE_WINDOW' => sub {&close_it_up});
$mw->fontCreate('big',
-family=>'courier',
-weight=>'bold',
-size=>int(-18*18/14));
my $cframe1 = $mw->Frame(-background =>'black')
->pack( -fill =>'x');
my $cframe2 = $mw->Frame(-background =>'black')
->pack( -fill =>'x');
my $canv = $mw->Scrolled('Canvas',
-bg => 'black',
-borderwidth => 0,
-highlightthickness => 0,
-relief => 'sunken',
-width => $width,
-height => $height,
-scrollregion=>[0,0,$width,$height],
+
-scrollbars=>'osoe',
)->pack();
## this Frame is needed for including the window in Tk::Canvas
my $Container = $canv->Frame(-container => 1);
my $xtid = $Container->id();
# converting the id from HEX to decimal as xterm requires a decimal Id
my ($xtId) = sprintf hex $xtid;
my $dcontitem = $canv->createWindow(10,10,
-anchor=>'nw',
-window => $Container,
-width => $width,
-height => $height,
-state => 'hidden',
-tags => ['viewport'],
);
my $pid;
my @options = (
'-slave','-loop 0', '-zoom',
"-x $width", "-y $height",
'-really-quiet',
"-wid $xtId",
"-vf screenshot",
"tv:// -tv driver=v4l2:device=/dev/video0:input=1:brightness=$brightn
+ess:amode=1:fps=$fps:width=$width:height=$height",
);
my $loadl_but = $cframe1->Button(-text => 'Snapshot',
-background => 'black',
-foreground => 'hotpink',
-activebackground => 'lightyellow',
-padx => 0,
-command => \&grab1,
-font => 'big'
)->pack(-side =>'left',-padx=>10 );
$cframe1->Button(-text => "Exit",
-background => 'black',
-foreground => 'hotpink',
-activebackground => 'lightyellow',
-padx => 0,
-command => [sub{&close_it_up}],
-font => 'big'
)->pack(-side=>'right', -padx =>10 );
$cframe1->Label(-text=>" Brightness->",
-background => 'black',
-foreground => 'lightgreen' )->pack (-side=>'left');
my $sp1 = $cframe1->Spinbox(-width => 4,
-font => 'big',
-background => 'black',
-buttonbackground => 'black',
-foreground => 'lightgreen',
-command => sub{ &set_brightness },
-from => -100,
-to => 100,
-textvariable => \$brightness,
)->pack (-side=>'left');
$cframe1->Label(-text=>" Contrast->",
-background => 'black',
-foreground => 'lightgreen' )->pack (-side=>'left');
my $sp2 = $cframe1->Spinbox(-width => 4,
-font => 'big',
-background => 'black',
-foreground => 'lightgreen',
-buttonbackground => 'black',
-command => sub{ &set_contrast },
-from => -100,
-to => 100,
-textvariable => \$contrast,
)->pack (-side=>'left');
$cframe1->Label(-text=>" Snapshots taken->",
-background => 'black',
-foreground => 'lightgreen' )->pack (-side=>'left');
$cframe1->Entry(-textvariable => \$snaps_taken,
-background => 'lightyellow',
-font => 'big',
-width => 2
)->pack( -side => 'left');
$cframe2->Label(-text => 'Hit SpaceBar to take snapshot q o
+r esc to exit ',
-background => 'black',
-foreground => 'lightgreen',
-font => 'big'
)->pack(-expand=>1 );
$mw->Tk::bind("<space>", \&grab1);
&start_player;
MainLoop();
#########################################################
##############################################################
sub start_player{
$pid = open(MP, "| mplayer @options >/dev/null 2>&1 ");
$canv->itemconfigure($dcontitem,-state => 'normal');
}
##############################################################
sub set_brightness{
#print "$brightness\n";
syswrite(MP, "brightness $brightness 1\n");
}
##############################################################
sub set_contrast{
# print "$contrast\n";
syswrite(MP, "contrast $contrast 1\n");
}
##############################################################
sub grab1{
syswrite(MP, "screenshot 0\n");
$snaps_taken++;
}
#############################################################
sub stop{
syswrite(MP, "quit\n");
close MP;
$canv->itemconfigure($dcontitem,-state => 'hidden');
killfam 9, $pid;
}
#################################################################
sub close_it_up{
&stop;
exit;
}
###################################################################
__END__