My overall goal is to stream my computer screen to another machine on the same local network.
I know taking a screenshot on osx with python has been asked before, specifically here, but I am not satisfied with the answers there. Namely, they are too slow. With my Retina Mac, I have at best 7fps. I currently capture the screenshot like this
def capture(path):
_, displays, count = CG.CGGetActiveDisplayList(1, None, None)
url = NSURL.fileURLWithPath_(path)
dest = Quartz.CGImageDestinationCreateWithURL(
url, LaunchServices.kUTTypeJPEG, 1, None)
properties = {
Quartz.kCGImagePropertyDPIWidth: 72,
Quartz.kCGImagePropertyDPIHeight: 72,
}
image = CG.CGDisplayCreateImage(displays[0])
Quartz.CGImageDestinationAddImage(dest, image, properties)
Quartz.CGImageDestinationFinalize(dest)
Which uses Quartz to capture a screenshot at 72 dpi and saves it to a file. Then, I send the image data over a Python socket.
My main question is, is there any obvious place where this process can be sped up? My main two speedup ideas are
- How can I send the data from a Quartz CGImageRef directly over the socket, without writing it to a file?
- Is there any faster way to capture the screenshot? I don't mind it being lower resolution.