Python - AndroidViewClient take snapshots in high FPS

352 Views Asked by At

I wanted to take snapshots of my device in 60 FPS using AndroidViewClient on Python, so I used the function device.takeSnapshot(reconnect=True) in a loop to do so. However, it appeared that the time consumption of this function is around 0.5 seconds which gives me 2 FPS. I think the re-connection is what it makes it long. So why the device disconnects automatically after taking one snapshot? Is there a way to keep the connection on? Is there any other way to improve time consumption and get higher FPS?

1

There are 1 best solutions below

0
On

Although it's not AndroidViewClient/culebra's objective to be a screenrecorder, I ran a test like this

device, serialno = ViewClient.connectToDeviceOrExit()
t = time.time()
for s in range(60):
    device.takeSnapshot(reconnect=True)
t1 = time.time()-t
print "t={} secs  r={} screenshots/sec".format(t1, 60/t1)

and on a fast phone (Pixel 3) it can take 60 screenshots in 15 secs or 4 FPS. Also, take into account that the screen size is 1080x2160 so there's a lot of bytes to transfer.

You can take a look at takeSnapshot() source code and see that there are some parts you can remove or change if you want to speed it up, like the PIL Image creation that could be deferred.