stages.video.filtering.motion_vector_backend#
Module Contents#
Classes#
Container for decoded video frames containing motion vector data. |
|
Container for motion detection results. |
Functions#
Check if a video has small motion. |
|
Decode video for motion detection. |
|
Compute a canonical flow from motion vectors. |
API#
- class stages.video.filtering.motion_vector_backend.DecodedData#
Container for decoded video frames containing motion vector data.
This class stores a list of decoded frames, each containing motion vector data, and the dimensions of the RGB decoded frame used to construct the flow vector.
- frame_size: torch.Size#
None
- frames: list[numpy.typing.NDArray]#
None
- get_major_size() int#
Calculate total size in bytes of all frames in the decoded data.
Returns: Total size in bytes.
- class stages.video.filtering.motion_vector_backend.MotionInfo#
Container for motion detection results.
This class stores the results of motion detection analysis, including:
Whether the video has small motion
The minimum motion value in a 256x256 patch
The global average motion value across the entire videoq
- global_mean: float#
None
- is_small_motion: bool#
None
- per_patch_min_256: float#
None
- exception stages.video.filtering.motion_vector_backend.VideoResolutionTooSmallError#
Bases:
ExceptionException raised when video resolution is below the minimum required size.
This error occurs when either the width or height of the video is less than the minimum resolution threshold required for motion detection.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- stages.video.filtering.motion_vector_backend.check_if_small_motion(
- mv_list: list[numpy.typing.NDArray],
- frame_shape: torch.Size,
- global_mean_threshold: float = 0.00098,
- per_patch_min_256_threshold: float = 1e-06,
- *,
- use_gpu: bool = False,
- batch_size: int = 256,
Check if a video has small motion.
This function checks if a video has small motion by calculating the global mean and per-pixel average motion values.
Args: mv_list: List of motion vectors. frame_shape: Shape of the frame. global_mean_threshold: Threshold for global mean motion. per_patch_min_256_threshold: Threshold for per-patch minimum motion. use_gpu: Whether to use GPU for computation. batch_size: Size of the batch for processing.
Returns: MotionInfo object containing the results of the motion detection.
- stages.video.filtering.motion_vector_backend.decode_for_motion(
- video: io.BytesIO,
- thread_count: int = 4,
- target_fps: float = 2.0,
- target_duration_ratio: float = 0.5,
Decode video for motion detection.
This function decodes a video stream to extract motion vectors.
Args: video: Input video stream as a bytes object. thread_count: Number of threads to use for decoding. target_fps: Target frames per second for motion detection. target_duration_ratio: Ratio of target duration to source duration.
Returns: DecodedData object containing motion vectors and frame dimensions.
- stages.video.filtering.motion_vector_backend.motion_vectors_to_flowfield(
- mvs: torch.Tensor,
- size: list[int],
- flow: torch.Tensor | None = None,
Compute a canonical flow from motion vectors.