Skip to content

y5gfunc.source.rpu

rpu

Classes:

Name Description
RpuFile

Represents a Dolby Vision RPU binary file.

Functions:

Name Description
write_rpu

Writes the RPU data to the clip.

RpuFile

RpuFile(file_path: Union[str, Path])

Represents a Dolby Vision RPU binary file.

Initializes the RpuFile instance.

Parameters:

Name Type Description Default

file_path

Union[str, Path]

Path to the RPU file.

required

Raises:

Type Description
FileNotFoundError

If the file path does not exist.

Methods:

Name Description
__len__
get_frame_data

Gets the payload of a single RPU frame by its index.

Attributes:

Name Type Description
file_path
Source code in y5gfunc/source/rpu.py
def __init__(self, file_path: Union[str, Path]) -> None:
    """
    Initializes the RpuFile instance.

    Args:
        file_path: Path to the RPU file.

    Raises:
        FileNotFoundError: If the file path does not exist.
    """
    self.file_path = resolve_path(file_path)
    self._data = b""
    self._nalu_offsets: list[int] = []

    self._load_and_parse()

file_path instance-attribute

file_path = resolve_path(file_path)

__len__

__len__() -> int
Source code in y5gfunc/source/rpu.py
def __len__(self) -> int:
    return len(self._nalu_offsets)

get_frame_data

get_frame_data(frame_index: int) -> bytes

Gets the payload of a single RPU frame by its index.

Parameters:

Name Type Description Default

frame_index

int

The 0-based index of the frame to retrieve.

required

Returns:

Type Description
bytes

The RPU payload binary data (starting with 0x19) for the requested frame.

Raises:

Type Description
IndexError

If frame_index is out of bounds.

ValueError

If the RPU payload (0x19) is not found within the frame.

Source code in y5gfunc/source/rpu.py
def get_frame_data(self, frame_index: int) -> bytes:
    """
    Gets the payload of a single RPU frame by its index.

    Args:
        frame_index: The 0-based index of the frame to retrieve.

    Returns:
        The RPU payload binary data (starting with 0x19) for the requested frame.

    Raises:
        IndexError: If frame_index is out of bounds.
        ValueError: If the RPU payload (0x19) is not found within the frame.
    """
    if not 0 <= frame_index < len(self._nalu_offsets):
        raise IndexError(
            f"Frame index {frame_index} is out of range. Valid indices are 0 to {len(self) - 1}."
        )

    start_offset = self._nalu_offsets[frame_index]

    if frame_index + 1 < len(self._nalu_offsets):
        end_offset = self._nalu_offsets[frame_index + 1]
    else:
        end_offset = len(self._data)

    frame_content_start = self._data.find(
        self._RPU_PAYLOAD_START_BYTE, start_offset, end_offset
    )

    if frame_content_start == -1:
        raise ValueError(
            f"Could not find RPU payload (0x19) in frame {frame_index}."
        )

    return self._data[frame_content_start:end_offset]

write_rpu

write_rpu(rpu_file_path: Union[str, Path], clip: VideoNode) -> VideoNode

Writes the RPU data to the clip.

Source code in y5gfunc/source/rpu.py
def write_rpu(rpu_file_path: Union[str, Path], clip: vs.VideoNode) -> vs.VideoNode:
    """
    Writes the RPU data to the clip.
    """
    rpu_file = RpuFile(rpu_file_path)

    def write_frame(n: int, f: vs.VideoFrame) -> vs.VideoFrame:
        rpu_data = rpu_file.get_frame_data(n)
        fout = f.copy()
        fout.props["DolbyVisionRPU"] = rpu_data
        return fout

    return clip.std.ModifyFrame(clip, selector=write_frame)