python_vali

python_vali

GetNumGpus()

Get number of available GPUs.

GetNvencParams()

Get list of params PyNvEncoder can be initialized with.

SetFFMpegLogLevel(arg0)

Set FFMpeg log level.

PySurfaceResizer

CUDA-accelerated Surface resizer.

PySurfaceDownloader

This class is used to copy Surface to numpy ndarray using CUDA DtoH memcpy.

PySurfaceConverter

CUDA-accelerated converter between different pixel formats.

PyNvEncoder

HW-accelerated video encoder which uses Nvenc.

PyDecoder

Video decoder class.

PyFrameUploader

This class is used to upload numpy array to Surface using CUDA HtoD memcpy.

PyNvJpegEncoder

SeekContext

Incapsulates information required by decoder to seek for a particular video frame.

SurfacePlane

Continious 2D chunk of memory stored in vRAM which represents single plane / channel of video frame.

Surface

Image stored in vRAM.

class python_vali._python_vali.ColorRange

Members:

MPEG : Narrow or MPEG color range. Doesn’t use full [0;255] range.

JPEG : Full of JPEG color range. Uses full [0;255] range.

UDEF : Undefined color range.

property name
class python_vali._python_vali.ColorSpace

Members:

BT_601 : BT.601 color space.

BT_709 : BT.709 color space.

UNSPEC : Unspecified color space.

property name
class python_vali._python_vali.ColorspaceConversionContext

Stores information required for accurate color conversion.

class python_vali._python_vali.CudaBuffer

General purpose data storage class in GPU memory.

Clone(self: python_vali._python_vali.CudaBuffer) python_vali._python_vali.CudaBuffer

Deep copy = CUDA mem alloc + CUDA mem copy.

Return type:

python_vali.CudaBuffer

CopyFrom(*args, **kwargs)

Overloaded function.

  1. CopyFrom(self: python_vali._python_vali.CudaBuffer, other: python_vali._python_vali.CudaBuffer, stream: int) -> None

    Copy content of another CudaBuffer into this CudaBuffer

    param other:

    other CudaBuffer

    param stream:

    CUDA stream to use

    rtype:

    None

  2. CopyFrom(self: python_vali._python_vali.CudaBuffer, other: python_vali._python_vali.CudaBuffer, gpu_id: int) -> None

    Copy content of another CudaBuffer into this CudaBuffer

    param other:

    other CudaBuffer

    param gpu_id:

    GPU to use for memcopy

    rtype:

    None

property ElemSize

Get size of single element in bytes

Return type:

Int

property GpuMem

Get CUdeviceptr of memory allocation.

Return type:

Int

static Make(elem_size: int, num_elems: int, gpu_id: int) python_vali._python_vali.CudaBuffer

Constructor method

Parameters:
  • elem_size – single buffer element size in bytes

  • num_elems – number of elements in buffer

  • gpu_id – GPU to use for memcopy

Return type:

python_vali.CudaBuffer

property NumElems

Get number of elements in buffer.

Return type:

Int

property RawMemSize

Get size of buffer in bytes.

Return type:

Int

class python_vali._python_vali.DLDeviceType

Members:

kDLCPU : CPU device.

kDLCUDA : CUDA GPU device.

kDLCUDAHost : Pinned CUDA CPU memory by cudaMallocHost.

kDLCUDAManaged : CUDA managed/unified memory allocated by cudaMallocManaged.

property name
class python_vali._python_vali.FfmpegLogLevel

Members:

PANIC : AV_LOG_PANIC

FATAL : AV_LOG_FATAL

ERROR : AV_LOG_ERROR

WARNING : AV_LOG_WARNING

INFO : AV_LOG_INFO

VERBOSE : AV_LOG_VERBOSE

DEBUG : AV_LOG_DEBUG

property name
python_vali._python_vali.GetNumGpus() int

Get number of available GPUs.

python_vali._python_vali.GetNvencParams() Dict[str, str]

Get list of params PyNvEncoder can be initialized with.

class python_vali._python_vali.MotionVector

This class stores iformation about motion vector.

property dst_x

Absolute detination X position. Can be outside frame area.

property dst_y

Absolute detination Y position. Can be outside frame area.

property h

Macroblock height

property motion_scale

Motion prediction precision. E. g. 4 for quarter-pixel precision.

property motion_x

Motion vector X component.

property motion_y

Motion vector Y component.

property source

Where the current macroblock comes from; negative value when it comes from the past, positive value when it comes from the future.

property src_x

Absolute source X position. Can be outside frame area.

property src_y

Absolute source Y position. Can be outside frame area.

property w

Macroblock width.

class python_vali._python_vali.NV_ENC_CAPS

Members:

NUM_MAX_BFRAMES

SUPPORTED_RATECONTROL_MODES

SUPPORT_FIELD_ENCODING

SUPPORT_MONOCHROME

SUPPORT_FMO

SUPPORT_QPELMV

SUPPORT_BDIRECT_MODE

SUPPORT_CABAC

SUPPORT_ADAPTIVE_TRANSFORM

SUPPORT_STEREO_MVC

NUM_MAX_TEMPORAL_LAYERS

SUPPORT_HIERARCHICAL_PFRAMES

SUPPORT_HIERARCHICAL_BFRAMES

LEVEL_MAX

LEVEL_MIN

SEPARATE_COLOUR_PLANE

WIDTH_MAX

HEIGHT_MAX

SUPPORT_TEMPORAL_SVC

SUPPORT_DYN_RES_CHANGE

SUPPORT_DYN_BITRATE_CHANGE

SUPPORT_DYN_FORCE_CONSTQP

SUPPORT_DYN_RCMODE_CHANGE

SUPPORT_SUBFRAME_READBACK

SUPPORT_CONSTRAINED_ENCODING

SUPPORT_INTRA_REFRESH

SUPPORT_CUSTOM_VBV_BUF_SIZE

SUPPORT_DYNAMIC_SLICE_MODE

SUPPORT_REF_PIC_INVALIDATION

PREPROC_SUPPORT

ASYNC_ENCODE_SUPPORT

MB_NUM_MAX

MB_PER_SEC_MAX

SUPPORT_YUV444_ENCODE

SUPPORT_LOSSLESS_ENCODE

SUPPORT_SAO

SUPPORT_MEONLY_MODE

SUPPORT_LOOKAHEAD

SUPPORT_TEMPORAL_AQ

SUPPORT_10BIT_ENCODE

NUM_MAX_LTR_FRAMES

SUPPORT_WEIGHTED_PREDICTION

DYNAMIC_QUERY_ENCODER_CAPACITY

SUPPORT_BFRAME_REF_MODE

SUPPORT_EMPHASIS_LEVEL_MAP

WIDTH_MIN

HEIGHT_MIN

SUPPORT_MULTIPLE_REF_FRAMES

SUPPORT_ALPHA_LAYER_ENCODING

EXPOSED_COUNT

property name
class python_vali._python_vali.PacketData

Video frame attributes

property bsl

Amount of bytes decoder had to consume to decode corresp. packet. Useful to see when seeking for a previous key frame.

property dts

Decode timestamp.

property duration

Duration of a packet.

property key

1 if frame is I frame, 0 otherwise.

property pos

Position of compressed packet in input bitstream.

property pts

Presentation timestamp.

class python_vali._python_vali.PixelFormat

Members:

Y : Grayscale.

RGB : Interleaved 8 bit RGB.

NV12 : Semi planar 8 bit: full resolution Y + quarter resolution interleaved UV.

YUV420 : Planar 8 bit: full resolution Y + quarter resolution U + quarter resolution V.

RGB_PLANAR : Planar 8 bit R+G+B.

BGR : Planar 8 bit R+G+B.

YUV444 : Planar 8 bit Y+U+V.

YUV444_10bit : 10 bit YUV444.

YUV420_10bit : 10 bit YUV420

UNDEFINED : Undefined pixel format, use to signal unsupported formats

RGB_32F : 32 bit float RGB.

RGB_32F_PLANAR : 32 bit float planar RGB

YUV422 : 8 bit planar: full resolution Y + half resolution U + half resolution V.

P10 : 10 bit NV12.

P12 : 12 bit NV12.

property name
class python_vali._python_vali.PyDecoder

Video decoder class.

property AvgFramerate

Return encoded video file average framerate.

property Bitrate

Return encoded video bitrate in bits per second.

property ColorRange

Get color range information stored in video file. Please not that some video containers may not store this information.

Returns:

color range information

property ColorSpace

Get color space information stored in video file. Please not that some video containers may not store this information.

Returns:

color space information

DecodeSingleFrame(*args, **kwargs)

Overloaded function.

  1. DecodeSingleFrame(self: python_vali._python_vali.PyDecoder, frame: numpy.ndarray, seek_ctx: Optional[python_vali._python_vali.SeekContext] = None) -> Tuple[bool, python_vali._python_vali.TaskExecInfo]

    Decode single video frame from input file. Only call this method for decoder without HW acceleration.

    param frame:

    decoded video frame

    param pkt_data:

    decoded video frame packet data, may be None

    param seek_ctx:

    seek context, may be None

    return:

    tuple, first element is True in case of success, False otherwise. Second elements is TaskExecInfo.

  2. DecodeSingleFrame(self: python_vali._python_vali.PyDecoder, frame: numpy.ndarray, pkt_data: python_vali._python_vali.PacketData, seek_ctx: Optional[python_vali._python_vali.SeekContext] = None) -> Tuple[bool, python_vali._python_vali.TaskExecInfo]

    Decode single video frame from input file. Only call this method for decoder without HW acceleration.

    param frame:

    decoded video frame

    param pkt_data:

    decoded video frame packet data, may be None

    param seek_ctx:

    seek context, may be None

    return:

    tuple, first element is True in case of success, False otherwise. Second elements is TaskExecInfo.

DecodeSingleSurface(*args, **kwargs)

Overloaded function.

  1. DecodeSingleSurface(self: python_vali._python_vali.PyDecoder, surf: VPF::Surface, seek_ctx: Optional[python_vali._python_vali.SeekContext] = None) -> Tuple[bool, python_vali._python_vali.TaskExecInfo]

    Decode single video surface from input file. Only call this method for HW-accelerated decoder.

    param surf:

    decoded video surface

    param pkt_data:

    decoded video surface packet data, may be None

    param seek_ctx:

    seek context, may be None

    return:

    tuple, first element is True in case of success, False otherwise. Second elements is TaskExecInfo.

  2. DecodeSingleSurface(self: python_vali._python_vali.PyDecoder, surf: VPF::Surface, pkt_data: python_vali._python_vali.PacketData, seek_ctx: Optional[python_vali._python_vali.SeekContext] = None) -> Tuple[bool, python_vali._python_vali.TaskExecInfo]

    Decode single video surface from input file. Only call this method for HW-accelerated decoder.

    param surf:

    decoded video surface

    param pkt_data:

    decoded video surface packet data, may be None

    param seek_ctx:

    seek context, may be None

    return:

    tuple, first element is True in case of success, False otherwise. Second elements is TaskExecInfo.

property Delay

Return encoded video delay.

property Duration

Return video duration time in seconds. May not be present.

property Format

Return encoded video file pixel format.

property Framerate

Return encoded video file framerate.

property GopSize

Return encoded video GOP size.

property Height

Return encoded video file height in pixels.

property HostFrameSize

Return amount of bytes needed to store decoded frame.

property IsAccelerated

Return true if decoder has HW acceleration support, false otherwise.

property IsVFR

Return true if video has variable framerate, false otherwise.

property Level

Return encoded video level coding parameter.

property Metadata

Return dictionary with video file metadata.

property MotionVectors
Return motion vectors of last decoded frame.

If there are no movion vectors it will return empty list.

Returns:

list of motion vectors

Return type:

List[vali.MotionVector]

property NumFrames

Return number of video frames in encoded video file. Please note that some video containers doesn’t store this infomation.

property NumStreams

audio and video.

Type:

Return number of streams in video file. E. g. 2 streams

property Profile

Return encoded video profile coding parameter.

property StartTime

Return video start time in seconds.

property StreamIndex

Return number of current video stream in file. E. g. video stream has index 0, and audio stream has index 1. This method will return 0 then.

property Timebase

Return encoded video file time base.

property Width

Return encoded video file width in pixels.

class python_vali._python_vali.PyFrameConverter

libswscale converter between different pixel formats.

property Format

Get pixel format.

Run(self: python_vali._python_vali.PyFrameConverter, src: numpy.ndarray, dst: numpy.ndarray, cc_ctx: python_vali._python_vali.ColorspaceConversionContext) Tuple[bool, python_vali._python_vali.TaskExecInfo]

Perform pixel format conversion.

Parameters:
  • src – input numpy ndarray, it must be of proper size for given format and resolution.

  • dst – output numpy ndarray, it may be resized to fit the converted frame.

  • cc_ctx – colorspace conversion context. Describes color space and color range used for conversion.

Returns:

tuple containing: success (Bool) True in case of success, False otherwise. info (TaskExecInfo) task execution information.

Return type:

tuple

class python_vali._python_vali.PyFrameUploader

This class is used to upload numpy array to Surface using CUDA HtoD memcpy.

Run(self: python_vali._python_vali.PyFrameUploader, src: numpy.ndarray, dst: VPF::Surface) Tuple[bool, python_vali._python_vali.TaskExecInfo]

Blocking HtoD CUDA memcpy.

Parameters:
  • src (numpy.ndarray) – input numpy array

  • dst (Surface) – output surface

Returns:

tuple containing: success (Bool) True in case of success, False otherwise. info (TaskExecInfo) task execution information.

Return type:

tuple

class python_vali._python_vali.PyNvEncoder

HW-accelerated video encoder which uses Nvenc.

property Capabilities

Return dictionary with Nvenc capabilities.

EncodeSingleSurface(*args, **kwargs)

Overloaded function.

  1. EncodeSingleSurface(self: python_vali._python_vali.PyNvEncoder, surface: VPF::Surface, packet: numpy.ndarray[numpy.uint8], sei: numpy.ndarray[numpy.uint8], sync: bool, append: bool) -> bool

    Encode single Surface. Please not that this function may not return compressed video packet.

    param surface:

    raw input Surface

    param packet:

    output compressed packet

    param sei:

    unregistered user data SEI information to be attached to encoded bitstream

    param sync:

    run function in sync mode, will ensure encoded packet is returned when function returns

    param append:

    append encoded packet to input packet

    return:

    True in case of success, False otherwise.

  2. EncodeSingleSurface(self: python_vali._python_vali.PyNvEncoder, surface: VPF::Surface, packet: numpy.ndarray[numpy.uint8], sei: numpy.ndarray[numpy.uint8], sync: bool) -> bool

    Encode single Surface. Please not that this function may not return compressed video packet.

    param surface:

    raw input Surface

    param packet:

    output compressed packet

    param sei:

    unregistered user data SEI information to be attached to encoded bitstream

    param sync:

    run function in sync mode, will ensure encoded packet is returned when function returns

    return:

    True in case of success, False otherwise.

  3. EncodeSingleSurface(self: python_vali._python_vali.PyNvEncoder, surface: VPF::Surface, packet: numpy.ndarray[numpy.uint8], sync: bool) -> bool

    Encode single Surface. Please not that this function may not return compressed video packet.

    param surface:

    raw input Surface

    param packet:

    output compressed packet

    param sync:

    run function in sync mode, will ensure encoded packet is returned when function returns

    return:

    True in case of success, False otherwise.

  4. EncodeSingleSurface(self: python_vali._python_vali.PyNvEncoder, surface: VPF::Surface, packet: numpy.ndarray[numpy.uint8], sei: numpy.ndarray[numpy.uint8]) -> bool

    Encode single Surface. Please not that this function may not return compressed video packet.

    param surface:

    raw input Surface

    param packet:

    output compressed packet

    param sei:

    unregistered user data SEI information to be attached to encoded bitstream

    return:

    True in case of success, False otherwise.

  5. EncodeSingleSurface(self: python_vali._python_vali.PyNvEncoder, surface: VPF::Surface, packet: numpy.ndarray[numpy.uint8]) -> bool

    Encode single Surface. Please not that this function may not return compressed video packet.

    param surface:

    raw input Surface

    param packet:

    output compressed packet

    return:

    True in case of success, False otherwise.

Flush(self: python_vali._python_vali.PyNvEncoder, packets: numpy.ndarray[numpy.uint8]) bool

Flush encoder. Use this method in the end of encoding session to obtain all remaining compressed frames.

Parameters:

packets – one or multiple compressed packets squashed together.

Returns:

True in case of success, False otherwise.

FlushSinglePacket(self: python_vali._python_vali.PyNvEncoder, packets: numpy.ndarray[numpy.uint8]) bool

Flush encoder. Use this method in the end of encoding session to obtain single remaining compressed frame. TO flush encoder completely you need to call this method multiple times.

Parameters:

packets – single compressed packet.

Returns:

True in case of success, False otherwise.

property Format

Return encoded video stream pixel format.

property FrameSizeInBytes

This function is used to get the current frame size based on pixel format.

property Height

Return encoded video stream height in pixels.

Reconfigure(self: python_vali._python_vali.PyNvEncoder, settings: Dict[str, str], force_idr: bool = False, reset_encoder: bool = False, verbose: bool = False) bool

DESC.

Parameters:
  • settings – Dictionary with nvenc settings

  • force_idr – force next encoded frame to be IDR key frame

  • reset_encoder – force encoder reset

  • verbose – output verbose information to log

Returns:

property Width

Return encoded video stream width in pixels.

class python_vali._python_vali.PySurfaceConverter

CUDA-accelerated converter between different pixel formats.

Run(self: python_vali._python_vali.PySurfaceConverter, src: VPF::Surface, dst: VPF::Surface, cc_ctx: Optional[python_vali._python_vali.ColorspaceConversionContext] = None) Tuple[bool, python_vali._python_vali.TaskExecInfo]

Perform pixel format conversion.

Parameters:
  • src – input Surface. Must be of same format class instance was created with.

  • dst – output Surface. Must be of suitable format.

  • cc_ctx – colorspace conversion context. Describes color space and color range used for conversion. Optional parameter. If not given, VALI will automatically pick supported color conversion parameters.

Returns:

tuple containing: success (Bool) True in case of success, False otherwise. info (TaskExecInfo) task execution information.

Return type:

tuple

class python_vali._python_vali.PySurfaceDownloader

This class is used to copy Surface to numpy ndarray using CUDA DtoH memcpy.

Run(self: python_vali._python_vali.PySurfaceDownloader, src: VPF::Surface, dst: numpy.ndarray) Tuple[bool, python_vali._python_vali.TaskExecInfo]

Perform DtoH memcpy.

Parameters:
  • src (Surface) – input Surface

  • dst (numpy.ndarray) – output numpy array

Returns:

tuple containing: success (Bool) True in case of success, False otherwise. info (TaskExecInfo) task execution information.

Return type:

tuple

class python_vali._python_vali.PySurfaceResizer

CUDA-accelerated Surface resizer.

Run(self: python_vali._python_vali.PySurfaceResizer, src: VPF::Surface, dst: VPF::Surface) Tuple[bool, python_vali._python_vali.TaskExecInfo]

Resize input Surface.

Parameters:
  • src – input Surface. Must be of same format class instance was created with.

  • dst – output Surface. Must be of same format class instance was created with.

Returns:

tuple containing: success (Bool) True in case of success, False otherwise. info (TaskExecInfo) task execution information.

Return type:

tuple

class python_vali._python_vali.SeekContext

Incapsulates information required by decoder to seek for a particular video frame.

property mode

by frame number or timestamp

Type:

Seek mode

property num_frames_decoded

Number of frames, decoded if seek was done to closest previous key frame.

property out_frame_pts

PTS of frame decoded after seek.

property seek_frame

Number of frame we want to seek.

property seek_tssec

Timestamp we want to seek.

class python_vali._python_vali.SeekMode

Members:

EXACT_FRAME : Use this to seek for exac frame. Notice that if it’s P or B frame, decoder may not be able to get it unless it reconstructs all the frames that desired frame use for reference.

PREV_KEY_FRAME : Seek for closes key frame in past.

property name
python_vali._python_vali.SetFFMpegLogLevel(arg0: python_vali._python_vali.FfmpegLogLevel) None

Set FFMpeg log level.

class python_vali._python_vali.Surface

Image stored in vRAM. Consists of 1+ SurfacePlane(s).

Clone(self: python_vali._python_vali.Surface) python_vali._python_vali.Surface

CUDA mem alloc + deep copy. Object returned is manager by Python interpreter.

property Format

Get pixel format

property Height

Height in pixels of plane 0.

property HostSize

Amount of memory in bytes which is needed for DtoH memcopy.

property IsEmpty

Tell if Surface plane has memory allocated or it’s empty inside.

property IsOwnMemory

Return True if Surface owns memory, False if it only references actual memory allocation but doesn’t own it.

static Make(*args, **kwargs)

Overloaded function.

  1. Make(format: python_vali._python_vali.PixelFormat, width: int, height: int, gpu_id: int) -> python_vali._python_vali.Surface

    Constructor method.

    param format:

    target pixel format

    param width:

    width in pixels

    param height:

    height in pixels

    param gpu_id:

    GPU to use

  2. Make(format: python_vali._python_vali.PixelFormat, width: int, height: int, context: int) -> python_vali._python_vali.Surface

    Constructor method.

    param format:

    target pixel format

    param width:

    width in pixels

    param height:

    height in pixels

    param context:

    CUDA contet to use

property NumPlanes

Number of SurfacePlanes

property Pitch

Pitch in bytes of plane 0.

property Planes

Get SurfacePlane reference

Parameters:

plane – SurfacePlane index

property Width

Width in pixels of plane 0.

static from_cai(dict: object, format: python_vali._python_vali.PixelFormat = <PixelFormat.RGB: 2>) python_vali._python_vali.Surface

DLPack: Make Surface from CAI, don not own memory.

Parameters:
  • dict – dictionary which corresponds to CUDA Array Interface specs.

  • fmt – pixel format, by default python_vali.PixelFormat.RGB

Returns:

Surface

Return type:

python_vali.Surface

static from_dlpack(capsule: capsule, format: python_vali._python_vali.PixelFormat = <PixelFormat.RGB: 2>) python_vali._python_vali.Surface

DLPack: Make Surface from dlpack, don not own memory.

Parameters:
  • capsule – capsule object with manager dltensor inside

  • fmt – pixel format, by default python_vali.PixelFormat.RGB

Returns:

Surface

Return type:

python_vali.Surface

class python_vali._python_vali.SurfacePlane

Continious 2D chunk of memory stored in vRAM which represents single plane / channel of video frame. It supports DLPack specification.

property ElemSize

Get element size in bytes

property GpuMem

Get pointer to SurfacePlane data

property Height

Get height in pixels

property HostFrameSize

Get amount of host memory needed to store this SurfacePlane

property Pitch

Get pitch in bytes

property Width

Get width in pixels

class python_vali._python_vali.TaskExecInfo

Members:

SUCCESS : Success

FAIL : Fail

END_OF_STREAM : End of file

MORE_DATA_NEEDED : More data needed to complete

BIT_DEPTH_NOT_SUPPORTED : Bit depth isn’t supported

INVALID_INPUT : Invalid input

UNSUPPORTED_FMT_CONV_PARAMS : Unsupported color conversion parameters

NOT_SUPPORTED : Unsupported feature

RES_CHANGE : Video resolution change happened

SRC_DST_SIZE_MISMATCH : Input and output size mismatch

property name