File size: 2,512 Bytes
eb09c29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
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."""

    # Video properties
    width, height = 320, 240
    fps = 30
    total_frames = duration_seconds * fps

    # Create video writer
    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):
        # Create a blank frame
        frame = np.zeros((height, width, 3), dtype=np.uint8)

        # Add background gradient
        for y in range(height):
            for x in range(width):
                frame[y, x] = [
                    int(255 * (x / width)),  # Red gradient
                    int(255 * (y / height)),  # Green gradient
                    128  # Blue constant
                ]

        # Add moving circle (simulates motion)
        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)

        # Add moving rectangle (more motion)
        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)

        # Add frame counter for debugging
        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)

    # Verify the file was created
    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")