python录制指定窗口的视频

可以使用 OpenCV 库来录制指定窗口的视频。下面是一个简单的代码示例:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))

while True:
    ret, frame = cap.read()
    if ret == True:
        frame = cv2.flip(frame, 0)