import cv2
from pathlib import Path
import numpy as np
Workspace = r"F:pythonProject测试ag包测试color_directory"
fourcc = cv2.VideoWriter.fourcc(*"MJPG")
video = cv2.VideoWriter(r"F:pythonProject测试压缩视频video1.avi", fourcc, 3, (2408, 1080))
for file in Path(Workspace).rglob("*.png"):
img = cv2.imdecode(np.fromfile(file, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
img = cv2.resize(img, (2408, 1080))
video.write(img)
cv2.destroyAllWindows()
video.release()