Python中的屏幕录制器
有没有什么库可以用来在Python中制作屏幕录制应用程序?我觉得做这样的东西会很有趣。不过,我需要一个可以在Linux上使用的库,因为我在用Ubuntu。
谢谢!
3 个回答
0
recordscreen.py 是一个命令行工具,它可以帮助你使用avconv(之前是ffmpeg)来录制和转换视频。用纯Python来实现这个功能会比较慢,但你当然可以为这些工具创建一些有用的绑定,或者改进现有的绑定,比如AVBin。
1
我不知道Python里有没有直接可以用来录屏的功能。不过,你可以用Python来控制一些已经存在的录屏软件:
- recorditnow
- recordmydesktop
- byzanz
- istanbul
- vnc2swf
- pyvnc2swf
2
使用MSS是用Python进行屏幕录制的一个很好的选择。
比如,使用这个来自 http://python-mss.readthedocs.io/examples.html 的代码,我得到了平均每秒60帧的效果。
import time
import cv2
import mss
import numpy
with mss.mss() as sct:
# Part of the screen to capture
monitor = {'top': 40, 'left': 0, 'width': 800, 'height': 640}
while 'Screen capturing':
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
cv2.imshow('OpenCV/Numpy normal', img)
# Display the picture in grayscale
# cv2.imshow('OpenCV/Numpy grayscale',
# cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
print('fps: {0}'.format(1 / (time.time()-last_time)))
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break