gpt4 book ai didi

Screen Recorded Through Python Script is Too fast(通过Python脚本录制的屏幕速度太快)

转载 作者:bug小助手 更新时间:2023-10-25 19:05:29 25 4
gpt4 key购买 nike



I could record the screen, but whenever I play the video it is very fast. How can I solve this issue?

我可以录制屏幕,但每当我播放视频时,它都非常快。我怎么才能解决这个问题呢?


import pyautogui
import cv2
import numpy as np

resolution = (1920, 1080)
codec = cv2.VideoWriter_fourcc(*"XVID")
filename = "Recording.avi"
fps = 60.0
out = cv2.VideoWriter(filename, codec, fps, resolution)
cv2.namedWindow("Live", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Live", 480, 270)
while True:
img = pyautogui.screenshot()
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
out.write(frame)
cv2.imshow('Live', frame)
if cv2.waitKey(1) == ord('q'):
break
time.sleep(1/30)
out.release()
cv2.destroyAllWindows()

更多回答

60 FPS requires each iteration to be 16 ms at most to keep up. You definitely won't achieve that when you waste 34 ms not doing anything (time.sleep), on top of acquiring, converting, compressing and displaying each FullHD frame.

60 FPS需要每次迭代最多16 ms才能跟上。当你浪费34毫秒不做任何事情(时间。睡眠),在获取,转换,压缩和显示每个FullHD帧的顶部时,你肯定不会实现这一点。

优秀答案推荐

There are a few things you can try to make the recorded video play at a normal speed. One possible solution is to reduce the number of frames per second (fps) that are being recorded. In your code, you are setting the fps value to 60.0, which is a very high value and may be causing the recorded video to play back too quickly. Try set fps to 25 or 30. Also you can try increasing the amount of time that the sleep() function is called, which will cause the loop to pause for a longer period of time between frames.

有几种方法可以尝试使录制的视频以正常速度播放。一种可能的解决方案是减少正在被记录的每秒帧数(Fps)。在您的代码中,您将fps值设置为60.0,这是一个非常高的值,可能会导致录制的视频播放得太快。尝试将fps设置为25或30。您还可以尝试增加调用SLEEP()函数的时间量,这将导致循环在两帧之间暂停更长的时间。



Your video playback is set to 60.0fps.

您的视频播放设置为60.0fps。


You are probably capturing frames at a much slower pace.

您可能正在以慢得多的速度捕捉帧。


let's say your "capture rate" is 20fps

假设你的“捕获率”是20fps


When you combine the frames into a 60fps video, the video will effectively be sped up by a factor of 1:3

当你将这些帧组合成60fps的视频时,视频的速度将有效地提高1:3


You have two solutions :

您有两种解决方案:


1. Slow Down your playback fps:

1.放慢播放fps:


As @a5zima noted, if you slow down your playback framerate to match your capture frame rate, you video will playback at normal speed (1:1).

正如@a5zima指出的那样,如果你放慢播放帧速率以匹配你的捕捉帧速率,你的视频将以正常速度(1:1)播放。


2.Speed up your capture:

2.加快抓捕速度:


You can also try to speed up the rate a which you capture the frames.
One way to achieve this is to use mss instead of pyautogui:

您还可以尝试加快捕获帧的速率。实现这一点的一种方法是使用MSS而不是PYOTOGUI:


import mss
import cv2
import numpy as np

resolution = (1920, 1080)
codec = cv2.VideoWriter_fourcc(*"XVID")
filename = "Recording.avi"
fps = 60.0
out = cv2.VideoWriter(filename, codec, fps, resolution)
cv2.namedWindow("Live", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Live", 480, 270)
while True:
sct = mss.mss()
img = sct.grab(mon)
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
out.write(frame)
cv2.imshow('Live', frame)
if cv2.waitKey(1) == ord('q'):
break
time.sleep(1/30)
out.release()
cv2.destroyAllWindows()

Of course, there might be even faster methods to do the capture, so you may need to explore alternatives if this still doesn't satisfy your needs.

当然,可能还有更快的方法来完成捕获,所以如果这仍然不能满足您的需求,您可能需要探索其他方法。


更多回答

"try increasing the amount of time that the sleep() function is called" -- having too much time (in order to waste some more) is certainly not a problem OP has.

“尝试增加调用睡眠()函数的时间”--有太多的时间(为了浪费更多的时间)肯定不是OP的问题。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com