Skip to content

video

video #

video_dataset — every stride-th frame of a posed video as a posed image.

video_dataset(video, stride=10, max_dimension=1600) #

Every stride-th frame of video as a posed image, decoded in one pass.

A kept frame carries the depth the sensor measured at it, Missing where it measured none. A frame without intrinsics is left out.

Parameters:

Name Type Description Default
video PosedVideo

The posed video.

required
stride int

Keep one frame in this many, starting from the first.

10
max_dimension int

The longest image side, in pixels, as written.

1600

Raises:

Type Description
ValueError

If stride is less than one.

Source code in capturegraph-recipes/capturegraph_recipes/splats/datasets/video.py
@cg.pure_function("splats.video_dataset/1")
def video_dataset(
    video: cg.PosedVideo,
    stride: int = 10,
    max_dimension: int = 1600,
) -> cg.Array[PosedImage]:
    """Every ``stride``-th frame of ``video`` as a posed image, decoded in one pass.

    A kept frame carries the depth the sensor measured at it, ``Missing``
    where it measured none. A frame without intrinsics is left out.

    Args:
        video: The posed video.
        stride: Keep one frame in this many, starting from the first.
        max_dimension: The longest image side, in pixels, as written.

    Raises:
        ValueError: If ``stride`` is less than one.
    """
    if stride < 1:
        raise ValueError(f"stride must be at least 1, got {stride}")
    kept = [frame for frame in list(video.frames())[::stride] if intrinsics(frame.pose) is not None]
    decoded = video.video.frames(frame.index for frame in kept)
    return cg.Array[PosedImage](
        [
            posed_frame(
                picture,
                frame.pose,
                cg.Missing if frame.depth is None else frame.depth,
                max_dimension,
            )
            for frame, (_, picture) in cg.logging.progress(
                zip(kept, decoded, strict=True),
                total=len(kept),
                label="Decoding frames",
            )
        ]
    )