#!/bin/sh # Copyright © 2001-2005 Jamie Zawinski # # 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. # # Created: 23-May-2001. PATH=/usr/local/bin:$PATH PATH=/home/jwz/src/slideshow:$PATH export PATH copyright=" DNA Lounge Live Webcam: http://www.dnalounge.com/cam/ %%DATE%% Copyright (c) %%YEAR%% by DNA Lounge, http://www.dnalounge.com/ Unauthorized use or reproduction prohibited. " progname=slideshow-grab file1="html/live.jpg" file2="html/live2.jpg" file3="html/live-thumb.jpg" tmp1="${file1}.~1~" tmp2="${file1}.~2~" # size of the resultant image width1=480 height1=360 width2=640 height2=480 width3=120 height3=90 rm -f "$tmp1" "$tmp2" check_for_signal() { lines=`od -b -w24 $1 | head -20 | wc -l` if [ "$lines" -lt 10 ]; then # The image must be all one color (blue, or black, or something.) # So there's no signal. So replace it with colorbars. djpeg < colorbars.jpg > $1 fi } grab_one() { year=`date '+%Y'` date=`date '+%a, %d-%b-%Y %l:%M:%S %p %Z'` tdate=`date '+%Y%m%d%H%M.%S'` copy=`echo "$copyright" | sed "s/%%YEAR%%/$year/;s/%%DATE%%/$date/"` # bttvgrab -N NTSC -d q -w $width2 -W $height2 -l 1 -o ppm -Q -f "$tmp1" # evidence suggests that bttvgrab eats my ass: let's try "streamer" from # the xawtv package now. (It requires the file name to end in .ppm.) # rm -f "$tmp1.ppm" # from xawtv # streamer -n NTSC -q -s "${width2}x${height2}" -o "$tmp1.ppm" 2>/dev/null # from http://ovcam.org/ov511/download/apps/w3cam-0.7.2.tar.gz # note: "-n ntsc" gets "ioctl (VIDIOCGCHAN): Invalid argument", so make sure # we've done "v4lctl setnorm ntsc" first (slideshow-grab-loop.sh does) vidcat -d /dev/video0 -b -f ppm -s "${width2}x${height2}" > "$tmp1.ppm" 2>/dev/null if [ \! -s "$tmp1.ppm" ]; then echo "$progname: no image grabbed" >&2 exit 1 fi mv "$tmp1.ppm" "$tmp2" # save away a large copy of the file... ppmnorm < "$tmp2" 2>/dev/null | cjpeg -q 90 > "$file2" # ...then scale it down, and go to work on the small version. pnmscale -xysize $width1 $height1 < "$tmp2" > "$tmp1" check_for_signal "$tmp1" ppmcaption "$tmp1" - \ -pos 10,-5 -left -text "DNA Lounge" \ -pos -10,-5 -right -text "$date" \ > "$tmp2" # create medium image cjpeg < "$tmp2" | wrjpgcom -replace -comment "$copy" > "$tmp1" touch -t "$tdate" "$tmp1" mv "$tmp1" "$file1" # create thumb image pnmscale -xysize $width3 $height3 < "$tmp2" | cjpeg -q 50 -opt > "$tmp1" touch -t "$tdate" "$tmp1" mv "$tmp1" "$file3" rm -f "$tmp2" # now that the medium image has been created, save away the large image # and the thumbnail. # slideshow-archive.pl $file2 $file3 # logger -t "$progname" "... `ls -lGFd $file2`" } grab_one exit 0