如何解决python中的屏幕录像机生成多个帧
我找到了应该是tp记录屏幕的代码。这是代码
import cv2
import numpy as np
import pyautogui
# display screen resolution,get it from your OS settings
SCREEN_SIZE = (1280,1024)
# define the codec
fourcc = cv2.VideoWriter_fourcc(*"XVID")
# create the video write object
out = cv2.VideoWriter("output.avi",fourcc,20.0,(SCREEN_SIZE))
while True:
# make a screenshot
img = pyautogui.screenshot()
# img = pyautogui.screenshot(region=(0,300,400))
# convert these pixels to a proper numpy array to work with OpenCV
frame = np.array(img)
# convert colors from BGR to RGB
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
# write the frame
out.write(frame)
# show the frame
cv2.imshow("screenshot",frame)
# if the user clicks q,it exits
if cv2.waitKey(1) == ord("q"):
break
# make sure everything is closed when exited
cv2.destroyAllWindows()
out.release()
该代码有效,但是对于Output.avi
文件,在观看它时,我注意到录制的屏幕中出现了多个帧。此外,在开始记录时如何最小化应用程序(.py)?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。