File size: 1,239 Bytes
1be2e5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

import cv2
import numpy as np
import pyautogui
import time
from datetime import datetime
import os

def record_demo():
    # Set up screen recording parameters
    output_file = 'demo_video.mp4'
    fps = 20.0
    
    # Get screen size
    screen_size = pyautogui.size()
    
    # Initialize video writer
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    out = cv2.VideoWriter(output_file, fourcc, fps, screen_size)
    
    print("Starting recording in 3 seconds...")
    time.sleep(3)
    
    try:
        # Record for 30 seconds
        start_time = time.time()
        duration = 30  # seconds
        
        while (time.time() - start_time) < duration:
            # Capture the screen
            screenshot = pyautogui.screenshot()
            frame = np.array(screenshot)
            
            # Convert from BGR to RGB
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            
            # Write the frame
            out.write(frame)
            
            # Maintain fps
            time.sleep(1/fps)
            
        print("Recording completed!")
        
    finally:
        # Release everything
        out.release()
        cv2.destroyAllWindows()

if __name__ == "__main__":
    record_demo()