|
|
|
|
|
""" |
|
|
Simple test video creator for TimeSformer testing. |
|
|
Creates a basic MP4 video with simple motion patterns. |
|
|
""" |
|
|
|
|
|
import cv2 |
|
|
import numpy as np |
|
|
from pathlib import Path |
|
|
|
|
|
def create_simple_test_video(output_path: str = "test_video.mp4", duration_seconds: int = 3): |
|
|
"""Create a simple test video with moving shapes.""" |
|
|
|
|
|
|
|
|
width, height = 320, 240 |
|
|
fps = 30 |
|
|
total_frames = duration_seconds * fps |
|
|
|
|
|
|
|
|
fourcc = cv2.VideoWriter_fourcc(*'mp4v') |
|
|
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height)) |
|
|
|
|
|
print(f"Creating test video: {output_path}") |
|
|
print(f"Duration: {duration_seconds} seconds, {total_frames} frames") |
|
|
|
|
|
for frame_num in range(total_frames): |
|
|
|
|
|
frame = np.zeros((height, width, 3), dtype=np.uint8) |
|
|
|
|
|
|
|
|
for y in range(height): |
|
|
for x in range(width): |
|
|
frame[y, x] = [ |
|
|
int(255 * (x / width)), |
|
|
int(255 * (y / height)), |
|
|
128 |
|
|
] |
|
|
|
|
|
|
|
|
progress = frame_num / total_frames |
|
|
center_x = int(50 + (width - 100) * progress) |
|
|
center_y = int(height // 2 + 30 * np.sin(progress * 4 * np.pi)) |
|
|
radius = 20 + int(10 * np.sin(progress * 6 * np.pi)) |
|
|
|
|
|
cv2.circle(frame, (center_x, center_y), radius, (255, 255, 255), -1) |
|
|
|
|
|
|
|
|
rect_x = int(width - 80 - (width - 160) * progress) |
|
|
rect_y = int(20 + 20 * np.cos(progress * 3 * np.pi)) |
|
|
cv2.rectangle(frame, |
|
|
(rect_x, rect_y), |
|
|
(rect_x + 40, rect_y + 30), |
|
|
(0, 255, 255), -1) |
|
|
|
|
|
|
|
|
cv2.putText(frame, f"Frame {frame_num}", (10, 30), |
|
|
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2) |
|
|
|
|
|
out.write(frame) |
|
|
|
|
|
out.release() |
|
|
print(f"β
Video created successfully: {output_path}") |
|
|
return output_path |
|
|
|
|
|
if __name__ == "__main__": |
|
|
output_file = "test_video.mp4" |
|
|
create_simple_test_video(output_file, duration_seconds=5) |
|
|
|
|
|
|
|
|
if Path(output_file).exists(): |
|
|
file_size = Path(output_file).stat().st_size |
|
|
print(f"File size: {file_size / 1024:.1f} KB") |
|
|
else: |
|
|
print("β Failed to create video file") |
|
|
|