video
Contains Video class and functions for validating and retrieving video properties.
Video
dataclass
Validate, set and store video properties such as the file path, dimensions, fps,
frame count, duration, filesize, and whether the video has audio. A validated
Video object is required to validate and calculate attributes in primary objects
and functions throughout.
Fields:
`filepath` (Path): Path to the video file.
Attributes:
`dimensions` (tuple[int, int]):
Dimensions of the video as (width, height).
`fps` (float):
Frame rate of the video.
`frame_count` (int):
Number of frames in the video.
`duration` (datetime.timedelta):
Duration of the video as a timedelta object.
`duration_seconds` (float):
Duration of the video in seconds.
`duration_timestamp` (str):
Duration of the video in `HH:MM:SS` format.
`has_audio` (bool):
True if the video has audio, False otherwise.
`filesize_bytes` (int):
Size of the video file in bytes.
`filesize` (str):
Size of the video file in a human-readable format.
validate_filepath
validate_filesize_bytes
Validate the video file size in bytes is a positive integer.
setattrs_from_opencap
Set the dimensions, fps and frame count read from an opened video capture.
Source code in videoxt/video.py
validate_dimensions
Validate the video frame width and height are positive integers.
Source code in videoxt/video.py
validate_fps
Validate the video fps is a positive float.
Source code in videoxt/video.py
validate_frame_count
Validate the video frame count is a positive integer.
Source code in videoxt/video.py
setattrs_duration
Set the duration attributes.
Source code in videoxt/video.py
setattr_filesize
setattr_has_audio
Set the has_audio attribute with moviepy.editor import VideoFileClip.audio
fetch_video_properties
Open the video file to retrieve and return the video's dimensions, fps, and frame count as a dictionary.
Args:
`filepath` (Path): Path to the video file.
Returns:
`dict[str, Any]`:
Dictionary containing unvalidated video properties:
- "dimensions" (tuple): Dimensions of the video as (width, height).
- "fps" (float): Frame rate of the video.
- "frame_count" (int): Number of frames in the video.
Source code in videoxt/video.py
open_video_capture
Context manager for opening a video file with cv2.VideoCapture.
Usage:
>>> from videoxt.video import open_video_capture
>>> with open_video_capture('path/to/video.mp4') as opencap:
... # do something with 'opencap'
... type(opencap)
<class 'cv2.VideoCapture'>
Args:
`filepath` (Path): Path to the video file.
Yields:
`cv2.VideoCapture`: An opened cv2 video capture.
Raises:
- `ClosedVideoCaptureError`:
- If `cv2.VideoCapture().isOpened()` returns False.
- If a `cv2.error` occurred while opening a `cv2.VideoCapture()`.
- For more details see:
https://docs.opencv.org/4.8.0/d8/dfe/classcv_1_1VideoCapture.html