Video Utils
Video utilities for frame extraction and video processing.
This module provides utility functions for working with video files, including frame extraction at specific timestamps.
extract_video_frame_at_timestamp(video_path, timestamp, output_format='PNG')
Extract a single frame from a video at a specific timestamp.
This function extracts a frame from a video file at the specified timestamp and returns it as raw image bytes in the specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_path
|
str
|
Path to the video file. |
required |
timestamp
|
float
|
Time offset in seconds from which to extract the frame. |
required |
output_format
|
str
|
Image format for the output (PNG, JPEG, etc.). Defaults to "PNG". |
'PNG'
|
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Raw image bytes in the specified format. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the video file doesn't exist. |
ValueError
|
If timestamp is negative or frame extraction fails. |
ImportError
|
If required libraries (cv2/opencv-python) are not installed. |
Examples:
>>> frame_bytes = extract_video_frame_at_timestamp("video.mp4", 5.5)
>>> frame_bytes = extract_video_frame_at_timestamp("video.mp4", 10.0, "JPEG")