VideosHelper Module¶
Convenience helpers for video I/O and frame access (OpenCV wrappers).
- class HMB.VideosHelper.VideosHelper[source]¶
Bases:
objectVideosHelper: Helpers for common video operations using OpenCV.
- Methods provided:
ReadVideo(videoPath)
WriteVideo(videoPath, frames, fps, frameSize, fourccType=”mp4v”)
ShowVideo(video, frameIndex)
ShowVideoFrames(video, frameIndexRange)
GetVideoFrames(video)
GetVideoFramesCount(video)
GetVideoFPS(video)
GetVideoFrameSize(video)
GetVideoFrameSizeString(video)
GetVideoDuration(video)
GetVideoFrame(video, frameIndex)
GetVideoFrameTime(video, frameIndex)
GetVideoFrameIndex(video, frameTime)
GetVideoFrameIndexRange(video, frameTimeRange)
GetVideoFrameTimeRange(video, frameIndexRange)
GetVideoFrameRange(video, frameIndexRange)
- ReadVideo(videoPath)[source]¶
Open a video file and return a cv2.VideoCapture object.
- Parameters:
videoPath (str) – Path to the video file.
- Returns:
Opened video capture object.
- Return type:
cv2.VideoCapture
- WriteVideo(videoPath, frames, fps, frameSize, fourccType='mp4v')[source]¶
Write a sequence of frames to a video file.
- ShowVideo(video, frameIndex)[source]¶
Display a single frame from a video using OpenCV GUI (blocking until a key press).
- Parameters:
video (cv2.VideoCapture) – Video capture object.
frameIndex (int) – Index of the frame to display.
- ShowVideoFrames(video, frameIndexRange)[source]¶
Display multiple frames by index range.
- Parameters:
video (cv2.VideoCapture) – Video capture object.
frameIndexRange (Iterable) – Iterable of frame indices to display.
- GetVideoFrames(video)[source]¶
Read all frames from an opened cv2.VideoCapture into a list.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
- Returns:
List of frames as NumPy arrays.
- Return type:
- GetVideoFramesCount(video)[source]¶
Get the total frame count of a video.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
- Returns:
Total number of frames (may be 0 for some live streams).
- Return type:
- GetVideoFPS(video)[source]¶
Return the frames-per-second (FPS) rate for the video.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
- Returns:
FPS value.
- Return type:
- GetVideoFrameSize(video)[source]¶
Get the video frame size as (width, height).
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
- Returns:
(width, height) in pixels.
- Return type:
- GetVideoFrameSizeString(video)[source]¶
Return a human-readable frame size string like “640x480”.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
- Returns:
Frame size string.
- Return type:
- GetVideoDuration(video)[source]¶
Estimate video duration in seconds using frame count and fps.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
- Returns:
Duration in seconds.
- Return type:
- GetVideoFrame(video, frameIndex)[source]¶
Retrieve a specific frame by index from an opened video.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
frameIndex (int) – Frame index.
- Returns:
Frame image array (BGR color by OpenCV convention).
- Return type:
- GetVideoFrameTime(video, frameIndex)[source]¶
Convert a frame index to its timestamp (in seconds) using FPS.
- GetVideoFrameIndex(video, frameTime)[source]¶
Convert a timestamp (seconds) to a fractional frame index.
- GetVideoFrameIndexRange(video, frameTimeRange)[source]¶
Convert a list/iterable of timestamps to frame indices.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
frameTimeRange (Iterable) – Iterable of timestamps in seconds.
- Returns:
List of frame indices (may be fractional).
- Return type:
- GetVideoFrameTimeRange(video, frameIndexRange)[source]¶
Convert a list/iterable of frame indices to timestamps.
- Parameters:
video (cv2.VideoCapture) – Opened video capture object.
frameIndexRange (Iterable) – Iterable of frame indices.
- Returns:
List of timestamps in seconds.
- Return type: