views:

1767

answers:

4
  • Are there any libraries to that can be used to write a screen capture in Python.
  • Can it be made to be cross-platform?
  • Is it possible to capture to video? And if could that be in real-time?
  • Or would it be possible to directly generate flash movies?
+2  A: 

I don't know of any general purpose libraries. I did this for windows and used some codeproject.com code in a DLL, called from ctypes.

Video capture is probably harder; I took screenshots really fast using the trivial codeproject way and got maybe 8fps. If that's not sufficient you are probably going to need a library that is optimized to your use case; e.g. tightVNC or CamStudio or something. CamStudio can export flash and is OSS.

Dustin Getz
+3  A: 

screen capture can be done with PIL thanks to the ImageGrab module

For generating Flash movies, you can have a look at ming. I am not sure that it has this capability but it worths a look.

luc
PIL's great, but unfortunately the ImageGrab module can only be used on Windows, according to their docs.
Donald Harvey
+1  A: 

One way to capture a video of the user's screen (certainly for X11, not sure about Windows) is to use gstreamer with the ximagesrc plugin. There are Python bindings available here, though I haven't used gst-python before. I know Istanbul, an open source screencasting app, uses it - viewing its source might help you.

To capture static images, I've used PyGTK before on Linux to capture the user's screen. This should also work on Windows and Mac, though I haven't tried it. Here's a small snippet:

import gtk
win = gtk.gdk.get_root_window()
width, height = win.get_size()
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
pb = pb.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0, width, height)
pb.save('path to file', 'png')

See the GTK docs for more info.

Hope that helps!

Donald Harvey
+1  A: 

you can try this also may be this URL can help you out.

its castro !!! see the sample code below may be useful....

>>> from castro import Castro
>>> c = Castro()
>>> c.start()
>>> # Do something awesome!
>>> c.stop()
Tumbleweed