From b9f147f3f72f0ce0eecf7e6598cad4b785aa4719 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 29 Dec 2010 17:03:42 +0000 Subject: refactored camera code to use poll for MESSAGE_EOS instead of timeout --- (limited to 'TurtleArt/tacamera.py') diff --git a/TurtleArt/tacamera.py b/TurtleArt/tacamera.py index a4227ed..2177288 100644 --- a/TurtleArt/tacamera.py +++ b/TurtleArt/tacamera.py @@ -22,14 +22,21 @@ import gst, time -def save_camera_input_to_file(imagepath, pause=2.0): - """ Grab a frame from the video camera and save to a temporary file """ +GST_PIPE = ['v4l2src', 'ffmpegcolorspace', 'pngenc'] - pipeline = gst.parse_launch( - 'v4l2src ! ffmpegcolorspace ! jpegenc ! filesink location=' + imagepath) - pipeline.set_state(gst.STATE_PLAYING) +class Camera(): + """ A class for representing the video camera """ - # Need to pause for pipeline to stablize - time.sleep(pause) + def __init__(self, imagepath): + GST_PIPE.append('filesink location=%s' % imagepath) + self.pipe = gst.parse_launch('!'.join(GST_PIPE)) + self.bus = self.pipe.get_bus() + + def save_camera_input_to_file(self): + """ Grab a frame from the camera """ + self.pipe.set_state(gst.STATE_PLAYING) + self.bus.poll(gst.MESSAGE_EOS, -1) + + def stop_camera_input(self): + self.pipe.set_state(gst.STATE_NULL) - pipeline.set_state(gst.STATE_NULL) -- cgit v0.9.1