录屏python代码来自chatgpt3.5

import pyautogui
import imageio

# Set the duration of the recording in seconds
duration = 10

# Specify the frames per second (FPS) for the video
fps = 10

# Specify the output file name
output_file = 'screen_recording.mp4'

# Get the screen resolution
screen_width, screen_height = pyautogui.size()

# Create a writer object to save the video
writer = imageio.get_writer(output_file, fps=fps)

try:
    for _ in range(int(fps * duration)):
        # Capture a screenshot
        screenshot = pyautogui.screenshot()

        # Convert the screenshot to a NumPy array
        frame = imageio.core.util.Array(screenshot)

        # Add the frame to the video
        writer.append_data(frame)
finally:
    # Close the writer to save the video
    writer.close()

print(f"Screen recording saved to {output_file}")