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

my first script #894

Open
khelmy55 opened this issue Nov 25, 2024 · 0 comments
Open

my first script #894

khelmy55 opened this issue Nov 25, 2024 · 0 comments

Comments

@khelmy55
Copy link

Hello,

below is my script:

import pyautogui
import cv2
import time
import numpy as np

def record_screen(filename, duration=30, width=1920, height=1080, fps=30):
    
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')  # Video codec
    out = cv2.VideoWriter(filename, fourcc, fps, (width, height))

    start_time = time.time()
    while time.time() - start_time < duration:
        img = pyautogui.screenshot()
        img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
        out.write(img)
        cv2.imshow('Screen Recorder', img)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    out.release()
    cv2.destroyAllWindows()

# Example usage:
filename = "test-01.mp4"
duration = 30  # Record for 30 seconds
record_screen(filename, duration)

when i run it, i get the screen recorded as displayed in the attached screenshot. what am i doing wrong and how to adjust the script so that the recording goes on until i stop it myself?

image

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