2 # Copyright © 2001, 2002, 2003, 2005 Jamie Zawinski <jwz@jwz.org>.
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation. No representations are made about the suitability of this
9 # software for any purpose. It is provided "as is" without express or
12 # This program attempts to grab a single frame of video from the system's
13 # video capture card, and then load it on to the root window using the
14 # "xscreensaver-getimage-file" program. Various frame-grabbing programs
15 # are known, and the first one found is used.
17 # The various xscreensaver hacks that manipulate images ("slidescreen",
18 # "jigsaw", etc.) get the image to manipulate by running the
19 # "xscreensaver-getimage" program.
21 # "xscreensaver-getimage" will invoke this program, depending on the
22 # value of the "grabVideoFrames" setting in the ~/.xscreensaver file
23 # (or in /usr/lib/X11/app-defaults/XScreenSaver).
25 # Created: 13-Apr-2001.
31 my $progname = $0; $progname =~ s@.*/@@g;
32 my $version = q{ $Revision: 1.16 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
36 my $tmpdir = $ENV{TMPDIR} || "/tmp";
37 my $tmpfile = sprintf ("%s/xssgv.%08x.ppm", $tmpdir, rand(0xFFFFFFFF));
40 # These are programs that can be used to grab a video frame. The first one
41 # of these programs that exists on $PATH will be used, and the image file
42 # is assumed to be written to $tmpfile (in some image format acceptable to
43 # "xscreensaver-getimage-file", e.g., PPM or JPEG.)
45 # If you add other programs to this list, please let me know!
49 "bttvgrab -d q -Q -l 1 -o ppm -f $tmpfile", # BTTV
50 "qcam > $tmpfile", # Connectix Qcam
51 "gqcam -t PPM -d $tmpfile", # GTK+ Qcam clone
53 "v4lctl snap ppm full $tmpfile", # XawTV 3.94.
55 "streamer -a -s 768x576 -o $tmpfile", # XawTV
56 # the "-a" option ("mute audio") arrived with XawTV 3.76.
58 "atitv snap $tmpfile", # ATI video capture card
60 "grab -type ppm -format ntsc -source 1 " . # *BSD BT848 module
61 "-settle 0.75 -output $tmpfile",
63 "motioneye -j $tmpfile", # Sony Vaio MotionEye
64 # (hardware jpeg encoder)
66 "vidcat -b -f ppm -s 640x480 > $tmpfile 2>-", # w3cam/ovcam
68 "vidtomem -f $tmpfile 2>&- " . # Silicon Graphics
69 "&& mv $tmpfile-00000.rgb $tmpfile",
75 print STDERR "$progname: $_\n";
79 my $displayer = undef;
84 foreach my $cmd (@programs) {
86 my ($name) = m/^([^ ]+)/;
87 push @names, "\"$name\"";
88 print STDERR "$progname: looking for $name...\n" if ($verbose > 2);
89 foreach my $dir (split (/:/, $ENV{PATH})) {
90 print STDERR "$progname: checking $dir/$name\n" if ($verbose > 3);
91 if (-x "$dir/$name") {
98 $names[$#names] = "or " . $names[$#names];
99 error "none of: " . join (", ", @names) . " were found on \$PATH.";
103 my $use_stdout_p = 0;
104 my $return_filename_p = 0;
107 my $cmd = pick_grabber();
110 print STDERR "$progname: executing \"$cmd\"\n" if ($verbose);
116 error "\"$cmd\" produced no data.";
119 if ($return_filename_p) {
120 print STDERR "$progname: wrote \"$tmpfile\"\n" if ($verbose);
121 print STDOUT "$tmpfile\n";
123 } elsif ($use_stdout_p) {
126 my $reader = "<$tmpfile";
128 # horrid kludge for SGIs, since they don't use PPM...
129 if ($displayer eq "vidtomem") {
130 $reader = "sgitopnm $tmpfile";
131 $reader .= " 2>/dev/null" if ($verbose <= 1);
135 open(IN, $reader) || error "reading $tmpfile: $!";
136 print STDERR "$progname: reading $tmpfile\n" if ($verbose > 1);
137 while (<IN>) { $ppm .= $_; }
144 $cmd = "xscreensaver-getimage-file";
145 $cmd .= " --verbose" if ($verbose);
148 print STDERR "$progname: executing \"$cmd\"\n" if ($verbose);
157 print STDERR "usage: $progname [--verbose] [--name | --stdout]\n";
162 while ($_ = $ARGV[0]) {
164 if ($_ eq "--verbose") { $verbose++; }
165 elsif (m/^-v+$/) { $verbose += length($_)-1; }
166 elsif (m/^--?stdout$/) { $use_stdout_p = 1; }
167 elsif (m/^--?name$/) { $return_filename_p = 1; }
168 elsif (m/^-./) { usage; }