I was trying to write a Python program that records current screen in arbitrary fps in OS X, say 60fps.
The fastest way to capture the current screen I found was using subprocess.call(["screencapture", "pic.bmp"]). But it took about 0.16 seconds to take a screenshot and so I couldn't get more than 6 fps by taking screenshots sequentially.
Instead, I tried to use Python's multiprocessing.Process (for the first time) to take screenshots by starting new processes at the interval of 0.0167s to make a 60fps video. I first tried to following code:
from multiprocessing import Process
from subprocess import call
from PIL import Image
import time
def capture(file_name):
call(["screencapture", file_name])
p1=Process(target=capture, args=("f1",))
p1.start()
p2=Process(target=capture, args=("f2",))
p2.start()
I tested the above code to take 2 pictures of the screen where Google's stopwatch is running. The resulting two pictures showed 0.05 seconds interval which would only be 12 fps at best.
Because there are screen recording programs like Monosnap which supports 60fps, I guess there should be a better way to do this and I'm trying to find how to speed this up. How could I bring down the interval to 0.0167 seconds or less?
Edit1: This is an update to respond to the claim that this is a possible duplicate of Take screenshots **quickly** from python. Actually there is FionaSarah's solution at PyGTK sample from the first link for the original question. But this solution doesn't seem to work with current version of Gdk in gi.repository of PyGObject. FionaSarah uses gtk.gdk.Pixbuf.get_from_drawable which is not found in the current version of Gdk. It seems Gtk.OffscreenWindow can be used instead or one should use use Xlib from this.