utils.nvcodec_utils
#
Module Contents#
Classes#
Policy for extracting frames from video, supporting full extraction or FPS-based sampling. |
|
Low-level NVIDIA hardware-accelerated video decoder. |
|
High-level frame extraction interface using PyNvVideoCodec. |
|
GPU-accelerated video decoder that processes video frames in batches. |
Functions#
Decode video frames for stitching using GPU acceleration. |
API#
- class utils.nvcodec_utils.FrameExtractionPolicy(*args, **kwds)#
Bases:
enum.Enum
Policy for extracting frames from video, supporting full extraction or FPS-based sampling.
This enum defines the available strategies for frame extraction from video content.
Initialization
- fps#
1
- full#
0
- class utils.nvcodec_utils.NvVideoDecoder(
- enc_file: str,
- device_id: int,
- batch_size: int,
- cuda_ctx: Any,
- cvcuda_stream: Any,
Low-level NVIDIA hardware-accelerated video decoder.
This class provides direct access to NVIDIA’s hardware video decoding capabilities, handling frame decoding and memory management for video processing pipelines.
Initialization
Create instance of HW-accelerated video decoder.
- Parameters:
enc_file – Full path to the MP4 file that needs to be decoded.
device_id – id of video card which will be used for decoding & processing.
cuda_ctx – A cuda context object.
- generate_decoded_frames() list[torch.Tensor] #
Generate decoded frames from the video.
Returns: List of decoded frames as tensors.
- get_next_frames() torch.Tensor | None #
Get the next frames from the video.
Returns: Next frames from the video as a tensor.
- class utils.nvcodec_utils.PyNvcFrameExtractor(width: int, height: int, batch_size: int)#
High-level frame extraction interface using PyNvVideoCodec.
This class provides a simplified interface for extracting frames from videos using hardware acceleration, supporting both full extraction and FPS-based sampling.
Initialization
Initialize the PyNvcFrameExtractor.
Args: width: Width of the video frames. height: Height of the video frames. batch_size: Number of frames to process in each batch.
- class utils.nvcodec_utils.VideoBatchDecoder(
- batch_size: int,
- target_width: int,
- target_height: int,
- device_id: int,
- cuda_ctx: str,
- cvcuda_stream: str,
GPU-accelerated video decoder that processes video frames in batches.
This class handles video decoding using NVIDIA hardware acceleration, supporting batch processing of frames with color space conversion and resizing capabilities.
Initialization
Initialize video batch decoder with GPU acceleration parameters.
Args: batch_size: Number of frames to process in each batch. target_width: Target width for decoded frames. target_height: Target height for decoded frames. device_id: GPU device ID to use. cuda_ctx: CUDA context for GPU operations. cvcuda_stream: CUDA stream for parallel processing.
- get_fps() int | None #
Get the frame rate of the video.
Returns: Frame rate of the video.
- utils.nvcodec_utils.gpu_decode_for_stitching(
- device_id: int,
- ctx: str,
- stream: int,
- input_path: pathlib.Path,
- frame_list: list[int],
- batch_size: int = 1,
Decode video frames for stitching using GPU acceleration.
Args: device_id: GPU device ID. ctx: CUDA context. stream: CUDA stream. input_path: Path to the video file to process. frame_list: List of frame indices to decode. batch_size: Number of frames to process in each batch.
Returns: List of decoded frames as tensors.