BoboTiG / python-mss

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
https://pypi.org/project/mss/
MIT License
1.01k stars 93 forks source link

How to capture the screen with a specific fps? #181

Closed hcao720 closed 1 year ago

hcao720 commented 4 years ago

Is there any way to capture the screen with a specific fps by applying mss?

sagarreddypatil commented 4 years ago

This better belongs on StackOverflow, but I'll answer the question anyways.

In order to run a python loop at a certain FPS, you can delay based on the time taken for a process.

import time
MAX_FPS=60
MIN_FRAME_TIME=1/MAX_FPS

while True:
  start = time.time()
  # screen capture
  time.sleep(max(0, MIN_FRAME_TIME - (time.time() - start)))

Hope this helps :)

hcao720 commented 4 years ago

Thanks!!!☺️

在 2020年10月22日,10:41,Sagar Patil notifications@github.com 写道:



This better belongs on StackOverflow, but I'll answer the question anyways.

In order to run a python loop at a certain FPS, you can delay based on the time taken for a process.

import time MAX_FPS=60 MIN_FRAME_TIME=1/MAX_FPS

while True: start = time.time()

screen capture

time.sleep(max(0, MIN_FRAME_TIME - (time.time() - start)))

Hope this helps :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BoboTiG/python-mss/issues/181#issuecomment-714184895, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMY3RA3NXH4XAJOTNG7FVRTSL6LWDANCNFSM4QAZVOZA.