#! /usr/bin/env python # $Id: v4l.py 25 2004-07-22 19:48:22Z peter $ import os import sys import time import util V4LDevice = '/dev/video0' V4LCTL = '/usr/bin/v4lctl -c ' + V4LDevice SnapshotRate = 3 # number of seconds between snapshots def command( cmd ): cmd = V4LCTL + ' ' + cmd ret = os.system( cmd ) def setup( ): command( ' setnorm NTSC' ) command( ' setinput Composite1' ) command( ' capture grabdisplay' ) command( ' color "50%"' ) command( ' hue "50%"' ) command( ' bright "50%"' ) command( ' contrast "50%"' ) def snapshot( file ): command( ' snap jpeg full ' + file ) def collect_snapshots( ): while 1: start_time = time.time( ) year, month, day, \ hour, minute, seconds, \ weekday, yearday, dst = time.localtime( start_time ) snapshot_name = '%d_%02d_%02d_%02d_%02d_%02d.jpg' % ( year, month, day, hour, minute, seconds ) fullname = util.log_path( os.path.join( '%d' % year, '%02d' % month, '%02d' % day, '%02d' % hour, '%02d' % minute ), snapshot_name ) snapshot( fullname ) end_time = time.time( ) time_difference = end_time - start_time if time_difference < SnapshotRate: time.sleep( SnapshotRate - time_difference ) if __name__ == '__main__': setup( ) if len( sys.argv ) == 1: collect_snapshots( ) else: snapshot( sys.argv[ 1 ] )