我的代码的问题是,保存视频后,它会大量加速,我注意到如果我更改cv2.waitkey()中的整数值,视频会改变速度,但是即使我将其设置为1仍在加速
import pyautogui
import os, cv2, threading
import numpy
import time
#paths
path_videos = os.chdir('C:/Users/mypcname/Desktop/screenrec/videos')
codec = cv2.VideoWriter_fourcc(\*XVID')
video_file = cv2.VideoWriter(os.getcwd()+ '\\' + 'VIDEO2' + '.avi', codec, 23.976, (1920, 1080))
def rec_loop():
global rec, path_videos, path_frames, frame_number, codec, video_file
while True:
#takes BGR screenshot and makes it in a NumPy array
capture = pyautogui.screenshot()
frame = numpy.array(capture)
#converts BGR screenshot into RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
#shows the recording screen live
cv2.imshow('REC', frame)
video_file.write(frame)
#cancel recording
if cv2.waitKey(250) == ord('Q'):
break
cv2.destroyAllWindows()
video_file.release()
rec_thread = threading.Thread(target=rec_loop)
rec_thread.start()
问题来源:stackoverflow
几件事...
You seem to start a new thread and then do nothing in parallel, so that is ostensibly not very sensible.
You will probably find that ` pyautogui ` can only capture around 2-3 frames per second, so you will only be passing them at that rate to videowriter, so they will appear speeded up. You could capture 2-10 frames before creating your output file and calculate the rate you achieve and pass that in.
You will be able to achieve a better framerate with ` ffmpeg ` , if that's what you want.
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。