nemo_rl.models.generation.vllm.video_utils#

Module Contents#

Functions#

_round_video_frame_count

_timestamp_to_video_frame_index

Convert a timestamp according to the configured sampling contract.

_select_video_frame_count

_compute_video_timestamps

_build_video_metadata

_resolve_cached_video_media_path

build_cached_video_frame_metadata

Return the shared synthetic timing contract for cached video frames.

build_cached_video_frame_data_url

Build a compact native-video URL backed by lossless cached PNG frames.

_load_cached_video_frame_manifest

Load an internal cached-frame manifest passed through vLLM VideoMediaIO.

_is_torchcodec_end_of_stream_error

_torchcodec_sample_indices

_find_torchcodec_decodable_frame_count

Find the decodable tail when container metadata overstates frame count.

_decode_torchcodec_video

Decode sampled frames, recovering from overstated container metadata.

_load_video_frames_torchcodec_with_metadata

Decode video with the repository’s optional TorchCodec dependency.

register_torchcodec_vllm_video_loader

Use TorchCodec for raw Nemotron video bytes parsed by vLLM’s HTTP server.

load_video_frames_with_metadata

Load sampled RGB frames through the supported TorchCodec backend.

Data#

API#

nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle#

None

nemo_rl.models.generation.vllm.video_utils._TORCHCODEC_END_OF_STREAM_ERROR#

‘Requested next frame while there are no more frames left to decode.’

nemo_rl.models.generation.vllm.video_utils._CACHED_VIDEO_FRAME_MANIFEST_MAGIC#

b’NEMO_RL_CACHED_VIDEO_FRAMES_V1\n’

nemo_rl.models.generation.vllm.video_utils._CACHED_VIDEO_FRAME_MANIFEST_MIME#

‘video/x-nemo-rl-cached-frames’

nemo_rl.models.generation.vllm.video_utils._round_video_frame_count(
num_frames: int,
*,
total_frames_in_file: int,
max_frames: int,
temporal_patch_size: int,
) int#
nemo_rl.models.generation.vllm.video_utils._timestamp_to_video_frame_index(
timestamp_s: float,
fps: float,
total_frames: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) int#

Convert a timestamp according to the configured sampling contract.

nemo_rl.models.generation.vllm.video_utils._select_video_frame_count(
*,
requested_num_frames: int,
total_frames_in_file: int,
temporal_patch_size: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) int#
nemo_rl.models.generation.vllm.video_utils._compute_video_timestamps(
total_duration: float,
num_frames: int,
total_frames_in_file: int,
original_num_frames: int,
temporal_patch_size: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) tuple[int, list[float]]#
nemo_rl.models.generation.vllm.video_utils._build_video_metadata(
*,
fps: float,
total_frames: int,
sampled_indices: list[int],
backend: str,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) dict[str, Any]#
nemo_rl.models.generation.vllm.video_utils._resolve_cached_video_media_path(value: str) pathlib.Path#
nemo_rl.models.generation.vllm.video_utils.build_cached_video_frame_metadata(
num_frames: int,
) dict[str, Any]#

Return the shared synthetic timing contract for cached video frames.

nemo_rl.models.generation.vllm.video_utils.build_cached_video_frame_data_url(frame_paths: list[str]) str#

Build a compact native-video URL backed by lossless cached PNG frames.

nemo_rl.models.generation.vllm.video_utils._load_cached_video_frame_manifest(
data: bytes,
*,
num_frames: int,
) tuple[numpy.ndarray, dict[str, Any]] | None#

Load an internal cached-frame manifest passed through vLLM VideoMediaIO.

nemo_rl.models.generation.vllm.video_utils._is_torchcodec_end_of_stream_error(exc: RuntimeError) bool#
nemo_rl.models.generation.vllm.video_utils._torchcodec_sample_indices(
*,
total_frames: int,
fps: float,
requested_num_frames: int,
temporal_patch_size: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) list[int]#
nemo_rl.models.generation.vllm.video_utils._find_torchcodec_decodable_frame_count(
decoder_factory: collections.abc.Callable[[], Any],
declared_total_frames: int,
) int#

Find the decodable tail when container metadata overstates frame count.

nemo_rl.models.generation.vllm.video_utils._decode_torchcodec_video(
source: Any,
*,
requested_num_frames: int,
temporal_patch_size: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
source_description: str,
initial_decoder: Any | None = None,
) tuple[numpy.ndarray, float, int, list[int]]#

Decode sampled frames, recovering from overstated container metadata.

nemo_rl.models.generation.vllm.video_utils._load_video_frames_torchcodec_with_metadata(
video_path: str,
*,
num_frames: int,
temporal_patch_size: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) tuple[numpy.ndarray, dict[str, Any]]#

Decode video with the repository’s optional TorchCodec dependency.

nemo_rl.models.generation.vllm.video_utils.register_torchcodec_vllm_video_loader(
*,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
temporal_patch_size: int,
) None#

Use TorchCodec for raw Nemotron video bytes parsed by vLLM’s HTTP server.

vLLM’s nemotron_vl loader defaults to OpenCV, while NeMo-RL deliberately does not ship OpenCV or PyAV. Registering this structural VideoLoader implementation under the same extension name keeps vLLM’s media connector contract and makes rollout decoding match policy-logprob preprocessing.

The caller supplies the same validated values materialized into the policy data configuration. Registration is therefore not conditional on process environment state.

nemo_rl.models.generation.vllm.video_utils.load_video_frames_with_metadata(
video_path: str,
*,
num_frames: int,
temporal_patch_size: int,
sampling_style: nemo_rl.models.generation.vllm.video_utils.VideoSamplingStyle,
) tuple[numpy.ndarray, dict[str, Any]]#

Load sampled RGB frames through the supported TorchCodec backend.