Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSS gives 4-5fps for video recording to be stored on disk #204

Open
hash3liZer opened this issue Aug 24, 2021 · 0 comments
Open

MSS gives 4-5fps for video recording to be stored on disk #204

hash3liZer opened this issue Aug 24, 2021 · 0 comments

Comments

@hash3liZer
Copy link

I've been trying to record a video using mss. As it claims, you can record a video at about more than 30, even 60 fps in some cases. However, i am finding it difficult to implement in practical.

I am using one of your examples from the documentation. I've extended it a bit to write a video on disk instead of showing it in a window using imshow method. Hope it explains the issue with mss.

So, this is my code:

import numpy as np
import cv2
from win32api import GetSystemMetrics
from mss.windows import MSS as mss

smonitor  = {"top": 0, "left": 0, "width": GetSystemMetrics(0), "height": GetSystemMetrics(1)}
codec       = cv2.VideoWriter_fourcc(*"vp80")
vwriter     = cv2.VideoWriter("file.webm", codec, 30.0, (GetSystemMetrics(0), GetSystemMetrics(1)))

with mss() as sct:
    try:
        while True:
           img = np.array(sct.grab(smonitor))
           vwriter.write(img)
    except KeyboardInterrupt:
           vwriter.release()

It does record the video. But as a matter of fact, this video won't be playable. It's a corrupted file. Now, apparently i need to run this line: cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) to actually record the video. So, the code would become:

with mss() as sct:
    try:
        while True:
           img = cv2.cvtColor(np.array(sct.grab(smonitor)), cv2.COLOR_BGR2RGB)
           vwriter.write(img)
    except KeyboardInterrupt:
           vwriter.release()

This time it works, but the max frames per second would be like 4 or at max it would be 5. So, we are back to the orignal issue. So, my question in simple is, how to use mss for recording a video?

  • OS name: Windows
  • OS version: 10
  • OS architecture: x64
  • Python version: 3.9
  • MSS version: 6.1.0
@hash3liZer hash3liZer changed the title MSS is gives 4-5fps for video recording to be stored on disk MSS gives 4-5fps for video recording to be stored on disk Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant