Now let’s create a simple typing simulation video!
1
Prepare a Python file
Create a simple Python file to simulate. For example, create hello.py:
hello.py
def greet(name): """Print a friendly greeting.""" print(f"Hello, {name}!") print("Welcome to VSCode Typing Simulator")if __name__ == "__main__": greet("World")
2
Run the capture script
Execute the main capture script:
python capture.py
3
Follow the prompts
The script will ask for three inputs:
Enter the file name to simulate (including .py extension): hello.pyEnter the output file name (without extension): my_first_videoEnter recording duration in seconds: 15
Don’t move your mouse or use the keyboard during recording. The process captures frames in real-time.
4
Wait for completion
The script will:
Display a 3-second countdown
Begin rendering the typing simulation
Save the output as my_first_video.avi
Progress is shown in the console as the video is being created.
Here’s what happens behind the scenes when you run capture.py:
capture.py
import timeimport cv2import numpy as npimport osimport pygamefrom vscode_mockup import VSCodeMockupdef record_video(source_file, output_file, duration): # Configure video capture screen_size = (1280, 720) # Fixed size for mockup # Use MJPG with AVI format for better compatibility fourcc = cv2.VideoWriter_fourcc(*'MJPG') out = cv2.VideoWriter( output_file + '.avi', fourcc, 30.0, screen_size ) if not out.isOpened(): print("Error: Could not initialize video recording.") return print("Recording started successfully") try: # Read source code with open(source_file, 'r', encoding='utf-8') as file: code = file.read() # Initialize mockup mockup = VSCodeMockup() # Simulate typing and record mockup.simulate_typing(code, out) finally: out.release() cv2.destroyAllWindows() pygame.quit()
The record_video function:
Initializes a video writer with MJPG codec at 30 FPS
Reads your Python source file
Creates a VSCode mockup interface
Simulates typing character by character while recording each frame