|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Generate a small test video for integration tests.""" |
| 3 | + |
| 4 | +import cv2 |
| 5 | +import numpy as np |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +def generate_test_video(): |
| 9 | + """Generate a small test video with 10 colored frames.""" |
| 10 | + output_path = Path(__file__).parent / "test_video.mp4" |
| 11 | + |
| 12 | + width, height = 640, 480 |
| 13 | + fps = 30 |
| 14 | + num_frames = 10 |
| 15 | + |
| 16 | + # Use H264 codec for compatibility |
| 17 | + fourcc = cv2.VideoWriter_fourcc(*'mp4v') |
| 18 | + out = cv2.VideoWriter(str(output_path), fourcc, fps, (width, height)) |
| 19 | + |
| 20 | + # Generate frames with different colors |
| 21 | + colors = [ |
| 22 | + (255, 0, 0), # Blue |
| 23 | + (0, 255, 0), # Green |
| 24 | + (0, 0, 255), # Red |
| 25 | + (255, 255, 0), # Cyan |
| 26 | + (255, 0, 255), # Magenta |
| 27 | + (0, 255, 255), # Yellow |
| 28 | + (128, 128, 128),# Gray |
| 29 | + (255, 255, 255),# White |
| 30 | + (0, 0, 0), # Black |
| 31 | + (128, 64, 32), # Brown |
| 32 | + ] |
| 33 | + |
| 34 | + for i in range(num_frames): |
| 35 | + # Create frame with solid color |
| 36 | + frame = np.full((height, width, 3), colors[i], dtype=np.uint8) |
| 37 | + |
| 38 | + # Add frame number text |
| 39 | + text = f"Frame {i+1}" |
| 40 | + cv2.putText(frame, text, (width//2 - 100, height//2), |
| 41 | + cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255), 3) |
| 42 | + |
| 43 | + out.write(frame) |
| 44 | + |
| 45 | + out.release() |
| 46 | + print(f"Generated test video: {output_path}") |
| 47 | + print(f"Size: {output_path.stat().st_size / 1024:.1f} KB") |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + generate_test_video() |
0 commit comments