summaryrefslogtreecommitdiffstats
path: root/hacks/xscreensaver-getimage-video
diff options
context:
space:
mode:
authorSimon Rettberg2021-04-06 14:23:46 +0200
committerSimon Rettberg2021-04-06 14:23:46 +0200
commit26b6e4255d4b9ff79a6dca10de5bec7bfc8691f9 (patch)
treea51e1637554bcd84e63cccb1cb220c898a2c4ee8 /hacks/xscreensaver-getimage-video
parent5.44 (diff)
downloadxscreensaver-26b6e4255d4b9ff79a6dca10de5bec7bfc8691f9.tar.gz
xscreensaver-26b6e4255d4b9ff79a6dca10de5bec7bfc8691f9.tar.xz
xscreensaver-26b6e4255d4b9ff79a6dca10de5bec7bfc8691f9.zip
xscreensaver 6.00
Diffstat (limited to 'hacks/xscreensaver-getimage-video')
-rwxr-xr-xhacks/xscreensaver-getimage-video141
1 files changed, 141 insertions, 0 deletions
diff --git a/hacks/xscreensaver-getimage-video b/hacks/xscreensaver-getimage-video
new file mode 100755
index 0000000..df13153
--- /dev/null
+++ b/hacks/xscreensaver-getimage-video
@@ -0,0 +1,141 @@
+#!/usr/bin/perl -w
+# Copyright © 2001-2015 Jamie Zawinski <jwz@jwz.org>.
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation. No representations are made about the suitability of this
+# software for any purpose. It is provided "as is" without express or
+# implied warranty.
+#
+# This program attempts to grab a single frame of video from the system's
+# video capture card, and then load it on to the root window using the
+# "xscreensaver-getimage-file" program. Various frame-grabbing programs
+# are known, and the first one found is used.
+#
+# The various xscreensaver hacks that manipulate images ("slidescreen",
+# "jigsaw", etc.) get the image to manipulate by running the
+# "xscreensaver-getimage" program.
+#
+# The various screen savers invoke "xscreensaver-getimage", which will in
+# turn invoke this program, depending on the value of the "grabVideoFrames"
+# setting in the ~/.xscreensaver file (or in the app-defaults file, usually
+# /usr/lib/X11/app-defaults/XScreenSaver).
+#
+# Created: 13-Apr-2001.
+
+require 5;
+#use diagnostics; # Fails on some MacOS 10.5 systems
+use strict;
+
+my $progname = $0; $progname =~ s@.*/@@g;
+my $version = q{ $Revision: 1.26 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
+
+my $tmpdir = $ENV{TMPDIR} || "/tmp";
+my $tmpfile = sprintf("%s/xssv.%08x.ppm", $tmpdir, rand(0xFFFFFFFF));
+
+my $verbose = 0;
+
+
+# These are programs that can be used to grab a video frame. The first one
+# of these programs that exists on $PATH will be used, and the image file
+# is assumed to be written to $tmpfile (in some image format acceptable to
+# "xscreensaver-getimage-file", e.g., PPM or JPEG.)
+#
+# If you add other programs to this list, please let me know!
+#
+my @programs = (
+
+ "bttvgrab -d q -Q -l 1 -o ppm -f $tmpfile", # BTTV
+ "qcam > $tmpfile", # Connectix Qcam
+ "gqcam -t PPM -d $tmpfile", # GTK+ Qcam clone
+
+ "v4lctl snap ppm full $tmpfile", # XawTV 3.94.
+ "streamer -a -o $tmpfile", # XawTV 3.76.
+ # "streamer -a -s 768x576 -o $tmpfile", # XawTV 3.75.
+
+ "atitv snap $tmpfile", # ATI video capture card
+
+ "grab -type ppm -format ntsc -source 1 " . # *BSD BT848 module
+ "-settle 0.75 -output $tmpfile",
+
+ "motioneye -j $tmpfile", # Sony Vaio MotionEye
+
+ "vidcat -b -f ppm -s 640x480 > $tmpfile 2>&-", # w3cam/ovcam
+
+ "vidtomem -f $tmpfile 2>&- " . # Silicon Graphics
+ "&& mv $tmpfile-00000.rgb $tmpfile",
+
+ "ffmpeg -y -v quiet -i /dev/video0 -vframes:v 1 $tmpfile 2>&-",
+
+ # "mplayer -really-quiet tv://0 " . # Maybe works with some cams?
+ # "-ao null -vo pnm -frames 1 2>&- " .
+ # "&& mv 00000001.ppm $tmpfile",
+
+);
+
+
+sub error($) {
+ my ($e) = @_;
+ print STDERR "$progname: $e\n";
+ exit 1;
+}
+
+sub pick_grabber() {
+ my @names = ();
+
+ foreach my $cmd (@programs) {
+ $_ = $cmd;
+ my ($name) = m/^([^ ]+)/;
+ push @names, "\"$name\"";
+ print STDERR "$progname: looking for $name...\n" if ($verbose > 2);
+ foreach my $dir (split (/:/, $ENV{PATH})) {
+ print STDERR "$progname: checking $dir/$name\n" if ($verbose > 3);
+ if (-x "$dir/$name") {
+ return $cmd;
+ }
+ }
+ }
+
+ $names[$#names] = "or " . $names[$#names];
+ error ("none of: " . join (", ", @names) . " were found on \$PATH.");
+}
+
+
+sub grab_image() {
+ my $cmd = pick_grabber();
+ unlink $tmpfile;
+
+ print STDERR "$progname: executing \"$cmd\"\n" if ($verbose);
+ system ($cmd);
+
+ if (! -s $tmpfile) {
+ unlink $tmpfile;
+ error ("\"$cmd\" produced no data.");
+ }
+
+ print STDERR "$progname: wrote \"$tmpfile\"\n" if ($verbose);
+ print STDOUT "$tmpfile\n";
+}
+
+
+sub usage() {
+ print STDERR "usage: $progname [--verbose] [--name]\n";
+ exit 1;
+}
+
+sub main() {
+ while ($_ = $ARGV[0]) {
+ shift @ARGV;
+ if (m/^--?verbose$/s) { $verbose++; }
+ elsif (m/^-v+$/s) { $verbose += length($_)-1; }
+ elsif (m/^--?name$/s) { } # ignored, for compatibility
+ elsif (m/^-./) { usage; }
+ else { usage; }
+ }
+ grab_image();
+}
+
+main;
+exit 0;