2 # Copyright © 2001, 2002, 2003 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).
31 my $progname = $0; $progname =~ s@.*/@@g;
32 my $version = q{ $Revision: 1.13 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
36 # These are programs that can be used to grab a video frame. The first one
37 # of these programs that exists on $PATH will be used, and the image file
38 # is assumed to be written to stdout (in some image format acceptable to
39 # "xscreensaver-getimage-file", e.g., PPM or JPEG.)
41 # If you add other programs to this list, please let me know!
44 my $tmpdir = $ENV{TMPDIR};
45 $tmpdir = "/tmp" unless $tmpdir;
47 my $tmpfile = sprintf ("%s/xssgv.%08x.ppm", $tmpdir, rand(0xFFFFFFFF));
49 # this crap is because "vidtomem" can only write to a file, and uses
50 # a stupid, non-overridable file name format.
51 my $sgi_bogosity = "$tmpfile-00000.rgb";
55 "bttvgrab -d q -Q -l 1 -o ppm -f $tmpfile", # BTTV
56 "qcam > $tmpfile", # Connectix Qcam
57 "gqcam -t PPM -d $tmpfile", # GTK+ Qcam clone
59 "streamer -a -s 768x576 -o $tmpfile", # XawTV
60 # the "-a" option ("mute audio") arrived with XawTV 3.76.
62 "atitv snap $tmpfile", # ATI video capture card
64 "grab -type ppm -format ntsc -source 1 " .
65 "-settle 0.75 -output $tmpfile", # *BSD BT848 module
67 "motioneye -j $tmpfile", # Sony Vaio MotionEye
68 # (hardware jpeg encoder)
70 "vidtomem -f $tmpfile 2>&- && mv $sgi_bogosity $tmpfile", # Silicon Graphics
76 print STDERR "$progname: $_\n";
80 my $displayer = undef;
85 foreach my $cmd (@programs) {
87 my ($name) = m/^([^ ]+)/;
88 push @names, "\"$name\"";
89 print STDERR "$progname: looking for $name...\n" if ($verbose > 2);
90 foreach my $dir (split (/:/, $ENV{PATH})) {
91 print STDERR "$progname: checking $dir/$name\n" if ($verbose > 3);
92 if (-x "$dir/$name") {
99 $names[$#names] = "or " . $names[$#names];
100 error "none of: " . join (", ", @names) . " were found on \$PATH.";
104 my $use_stdout_p = 0;
105 my $return_filename_p = 0;
108 my $cmd = pick_grabber();
111 print STDERR "$progname: executing \"$cmd\"\n" if ($verbose);
117 error "\"$cmd\" produced no data.";
120 if ($return_filename_p) {
121 print STDERR "$progname: wrote \"$tmpfile\"\n" if ($verbose);
122 print STDOUT "$tmpfile\n";
124 } elsif ($use_stdout_p) {
127 my $reader = "<$tmpfile";
129 # horrid kludge for SGIs, since they don't use PPM...
130 if ($displayer eq "vidtomem") {
131 $reader = "sgitopnm $tmpfile";
132 $reader .= " 2>/dev/null" if ($verbose <= 1);
136 open(IN, $reader) || error "reading $tmpfile: $!";
137 print STDERR "$progname: reading $tmpfile\n" if ($verbose > 1);
138 while (<IN>) { $ppm .= $_; }
145 $cmd = "xscreensaver-getimage-file";
146 $cmd .= " --verbose" if ($verbose);
149 print STDERR "$progname: executing \"$cmd\"\n" if ($verbose);
158 print STDERR "usage: $progname [--verbose] [--name | --stdout]\n";
163 while ($_ = $ARGV[0]) {
165 if ($_ eq "--verbose") { $verbose++; }
166 elsif (m/^-v+$/) { $verbose += length($_)-1; }
167 elsif (m/^--?stdout$/) { $use_stdout_p = 1; }
168 elsif (m/^--?name$/) { $return_filename_p = 1; }
169 elsif (m/^-./) { usage; }