from pathlib import Path
import cv2
import numpy as np

out_path = Path('uploads') / 'test_video.mp4'
width, height = 320, 240
fps = 15
length_seconds = 3
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(str(out_path), fourcc, fps, (width, height))

for i in range(fps * length_seconds):
    frame = np.zeros((height, width, 3), dtype=np.uint8)
    # moving colored square
    x = int((i * 5) % (width - 50))
    cv2.rectangle(frame, (x, 60), (x+50, 110), (0, 200, 100), -1)
    cv2.putText(frame, f'Frame {i+1}', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (200,200,200), 2)
    out.write(frame)

out.release()
print('WROTE', out_path)
