Images vs Video
Video is a sequence of images called frames. Understanding the relationship between images and video frames is the foundation of all video-based Computer Vision.
Video as a Sequence of Frames
A video is a sequence of individual images (frames) displayed rapidly to create the illusion of movement.
Key concepts:
- Frame: one single image in the video sequence
- FPS (Frames Per Second): how many frames are shown per second
- 24 FPS: cinema standard
- 30 FPS: standard video
- 60 FPS: smooth motion
- 120+ FPS: high-speed/slow-motion
- Resolution: the dimensions of each frame (e.g., 1920×1080)
- Codec: the compression format (H.264, H.265, VP9)
For Computer Vision, video processing means:
- Reading video frame by frame
- Processing each frame as a regular image
- Optionally using temporal information (how frames change over time)
A 1-minute 30fps video = 1,800 individual frames to process.
Machine Learning follows a structured pipeline from data to deployment
Video Properties
import cv2
# Open a video file
cap = cv2.VideoCapture("video.mp4")
if not cap.isOpened():
print("Error: Could not open video")
else:
# Read video properties
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = total / fps if fps > 0 else 0
print(f"Resolution: {width}x{height}")
print(f"FPS: {fps:.1f}")
print(f"Total frames:{total:,}")
print(f"Duration: {duration:.1f} seconds")
print(f"Codec: {int(cap.get(cv2.CAP_PROP_FOURCC))}")
# Read one frame to confirm it works
ret, frame = cap.read()
if ret:
print(f"Frame shape: {frame.shape}")
cap.release()