PyNvCodec.PyNvEncoder

class PyNvCodec.PyNvEncoder
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: PyNvCodec._PyNvCodec.PyNvEncoder, settings: Dict[str, str], gpu_id: int, format: PyNvCodec._PyNvCodec.PixelFormat = <PixelFormat.NV12: 3>, verbose: bool = False) -> None

    Constructor method.

    param settings:

    Dictionary with nvenc settings

    param gpu_id:

    what GPU to run encode on

    param format:

    pixel format to use by codec

    param verbose:

    output verbose information to log

  2. __init__(self: PyNvCodec._PyNvCodec.PyNvEncoder, settings: Dict[str, str], context: int, stream: int, format: PyNvCodec._PyNvCodec.PixelFormat = <PixelFormat.NV12: 3>, verbose: bool = False) -> None

    Constructor method.

    param settings:

    Dictionary with nvenc settings

    param context:

    CUDA context to use

    param stream:

    CUDA stream to use

    param format:

    pixel format to use by codec

    param verbose:

    output verbose information to log

Methods

Capabilities(self)

Return dictionary with Nvenc capabilities.

EncodeSingleFrame(*args, **kwargs)

Overloaded function.

EncodeSingleSurface(*args, **kwargs)

Overloaded function.

Flush(self, packets)

Flush encoder.

FlushSinglePacket(self, packets)

Flush encoder.

Format(self)

Return encoded video stream pixel format.

GetFrameSizeInBytes(self)

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

Height(self)

Return encoded video stream height in pixels.

Reconfigure(self, settings[, force_idr, ...])

DESC.

Width(self)

Return encoded video stream width in pixels.

__init__(*args, **kwargs)

Overloaded function.

Capabilities(self: PyNvCodec._PyNvCodec.PyNvEncoder) Dict[PyNvCodec._PyNvCodec.NV_ENC_CAPS, int]

Return dictionary with Nvenc capabilities.

EncodeSingleFrame(*args, **kwargs)

Overloaded function.

  1. EncodeSingleFrame(self: PyNvCodec._PyNvCodec.PyNvEncoder, frame: numpy.ndarray[numpy.uint8], packet: numpy.ndarray[numpy.uint8], sei: numpy.ndarray[numpy.uint8], sync: bool, append: bool) -> bool

    Combination of UploadSingleFrame + EncodeSingleSurface.

    param frame:

    raw video frame

    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. EncodeSingleFrame(self: PyNvCodec._PyNvCodec.PyNvEncoder, frame: numpy.ndarray[numpy.uint8], packet: numpy.ndarray[numpy.uint8], sei: numpy.ndarray[numpy.uint8], sync: bool) -> bool

    Combination of UploadSingleFrame + EncodeSingleSurface.

    param frame:

    raw video frame

    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. EncodeSingleFrame(self: PyNvCodec._PyNvCodec.PyNvEncoder, frame: numpy.ndarray[numpy.uint8], packet: numpy.ndarray[numpy.uint8], sync: bool) -> bool

    Combination of UploadSingleFrame + EncodeSingleSurface.

    param frame:

    raw video frame

    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. EncodeSingleFrame(self: PyNvCodec._PyNvCodec.PyNvEncoder, frame: numpy.ndarray[numpy.uint8], packet: numpy.ndarray[numpy.uint8], sei: numpy.ndarray[numpy.uint8]) -> bool

    Combination of UploadSingleFrame + EncodeSingleSurface.

    param frame:

    raw video frame

    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. EncodeSingleFrame(self: PyNvCodec._PyNvCodec.PyNvEncoder, frame: numpy.ndarray[numpy.uint8], packet: numpy.ndarray[numpy.uint8]) -> bool

    Combination of UploadSingleFrame + EncodeSingleSurface.

    param frame:

    raw video frame

    param packet:

    output compressed packet

    return:

    True in case of success, False otherwise.

EncodeSingleSurface(*args, **kwargs)

Overloaded function.

  1. EncodeSingleSurface(self: PyNvCodec._PyNvCodec.PyNvEncoder, nvcvimage: object, packet: numpy.ndarray[numpy.uint8], testbool: bool) -> bool

    Encode single Surface. Please note 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.

  2. EncodeSingleSurface(self: PyNvCodec._PyNvCodec.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.

  3. EncodeSingleSurface(self: PyNvCodec._PyNvCodec.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.

  4. EncodeSingleSurface(self: PyNvCodec._PyNvCodec.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.

  5. EncodeSingleSurface(self: PyNvCodec._PyNvCodec.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.

  6. EncodeSingleSurface(self: PyNvCodec._PyNvCodec.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: PyNvCodec._PyNvCodec.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: PyNvCodec._PyNvCodec.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.

Format(self: PyNvCodec._PyNvCodec.PyNvEncoder) PyNvCodec._PyNvCodec.PixelFormat

Return encoded video stream pixel format.

GetFrameSizeInBytes(self: PyNvCodec._PyNvCodec.PyNvEncoder) int

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

Height(self: PyNvCodec._PyNvCodec.PyNvEncoder) int

Return encoded video stream height in pixels.

Reconfigure(self: PyNvCodec._PyNvCodec.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:

Width(self: PyNvCodec._PyNvCodec.PyNvEncoder) int

Return encoded video stream width in pixels.