nvpipe

package module
v0.0.0-...-8a77d65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2020 License: BSD-3-Clause Imports: 2 Imported by: 2

README

Go wrapper for NvPipe

This package provides Go bindings for the NVIDIA Nvpipe libraries which is convenience wrapper around the low-level NVENC/NVDEC APIS in the official NVIDIA Video Codec SDK.

Import

go get github.com/KimJeongChul/nvpipe
import "github.com/KimJeongChul/nvpipe"

Encoding

const (
  codec = nvpipe.NvPipeH264
  format = nvpipe.NvPipeRGBA32
  compression = nvpipe.NvPipeLossless
  bitrateMbps = 32
  targetFPS = 30
  width = 1280
  height = 720
)

encoder := nvpipe.NewEncoder(format, codec, compression, bitrateMbps, targetFPS, width, height)
encodeSize := width * height
encodeData := make([]byte, encodeSize)
n := encoder.Encode(rgba.ToBytes(), encodeData)
if n == 0 {
  fmt.Println("[ERROR] nvenc error : ", encoder.GetError())
}

log.Println(encodeData[:n])

encoder.Destroy()

Decoding

const (
  codec = nvpipe.NvPipeH264
  format = nvpipe.NvPipeRGBA32
  width = 1280
  height = 720
  rgbaChannel = 4
)

decoder := nvpipe.NewDecoder(format, codec, width, height)
decodeSize := width*height*rgbaChannel
decodeData := make([]uint8, decodeSize)
n := decoder.Decode(encodeData, len(encodeData), decodeData)
if n == 0 {
  fmt.Println("[ERROR] nvdnc error : ", decoder.GetError())
}

log.Println(decodeData[:n]) 

decoder.Destroy()

Build & Installation

This package requires NVIDIA CUDA.

Documentation

Index

Constants

View Source
const (
	// NvPipeH264 H264 Codec
	NvPipeH264 = NvPipeCodec(C.NVPIPE_H264)
	// NvPipeHEVC HEVC/H265 Codec
	NvPipeHEVC = NvPipeCodec(C.NVPIPE_HEVC)
)
View Source
const (
	// NvPipeLossy ...
	NvPipeLossy = NvPipeCompression(C.NVPIPE_LOSSY)
	// NvPipeLossless produces larger output.
	NvPipeLossless = NvPipeCompression(C.NVPIPE_LOSSLESS)
)
View Source
const (
	// NvPipeRGBA32 RGBA32 format
	NvPipeRGBA32 = NvPipeFormat(C.NVPIPE_RGBA32)
	// NvPipeUInt4 uint4 format
	NvPipeUInt4 = NvPipeFormat(C.NVPIPE_UINT4)
	// NvPipeUInt8 uint8 format
	NvPipeUInt8 = NvPipeFormat(C.NVPIPE_UINT8)
	// NvPipeUInt16 uint16 format
	NvPipeUInt16 = NvPipeFormat(C.NVPIPE_UINT16)
	// NvPipeUInt32 uint32 format
	NvPipeUInt32 = NvPipeFormat(C.NVPIPE_UINT32)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder ...

func NewDecoder

func NewDecoder(format NvPipeFormat, codec NvPipeCodec, width int, height int) *Decoder

NewDecoder Create a new decoder instance. *

  • @param format Format of output frame.
  • @param codec Possible codecs are H.264 and HEVC if available.
  • @param width Initial width of the decoder.
  • @param height Initial height of the decoder.
  • @return NULL on error.

func (*Decoder) Decode

func (decoder *Decoder) Decode(src []byte, srcSize int, dst []uint8) int

Decode a single frame to device or host memory. *

  • @param nvp Decoder instance.
  • @param src Compressed frame data in host memory.
  • @param srcSize Size of compressed data.
  • @param dst Device or host memory pointer.
  • @param width Width of frame in pixels.
  • @param height Height of frame in pixels.
  • @return Size of decoded data in bytes or 0 on error.

func (*Decoder) Destroy

func (decoder *Decoder) Destroy()

Destroy Cleans up an decoder instance.

func (*Decoder) GetError

func (decoder *Decoder) GetError() string

GetError Returns an error message for the last error that occured. *

  • @return Returned string must not be deleted.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder ...

func NewEncoder

func NewEncoder(format NvPipeFormat, codec NvPipeCodec, compression NvPipeCompression, bitrateMbps int, targetFPS int, width int, height int) *Encoder

NewEncoder Creates a new encoder instance. *

  • @param format Format of input frame.
  • @param codec Possible codecs are H.264 and HEVC if available.
  • @param compression Lossy or lossless compression.
  • @param bitrate Bitrate in bit per second, e.g., 32 * 1000 * 1000 = 32 Mbps (for lossy compression only).
  • @param targetFrameRate At this frame rate the effective data rate approximately equals the bitrate (for lossy compression only).
  • @param width Initial width of the encoder.
  • @param height Initial height of the encoder.
  • @return NULL on error.

func (*Encoder) Destroy

func (encoder *Encoder) Destroy()

Destroy Cleans up an encoder instance.

func (*Encoder) Encode

func (encoder *Encoder) Encode(src []uint8, dst []byte) int

Encode a single frame from device or host memory. *

  • @param nvp Encoder instance.
  • @param src Device or host memory pointer.
  • @param srcPitch Pitch of source memory.
  • @param dst Host memory pointer for compressed output.
  • @param dstSize Available space for compressed output.
  • @param width Width of input frame in pixels.
  • @param height Height of input frame in pixels.
  • @param forceIFrame Enforces an I-frame instead of a P-frame.
  • @return Size of encoded data in bytes or 0 on error.

func (*Encoder) GetError

func (encoder *Encoder) GetError() string

GetError Returns an error message for the last error that occured. *

  • @return Returned string must not be deleted.

func (*Encoder) SetBitrate

func (encoder *Encoder) SetBitrate(bitrate int, targetFrameRate int)

SetBitrate Reconfigures the encoder with a new bitrate and target frame rate. *

  • @param nvp Encoder instance.
  • @param bitrate Bitrate in bit per second, e.g., 32 * 1000 * 1000 = 32 Mbps (for lossy compression only).
  • @param targetFrameRate At this frame rate the effective data rate approximately equals the bitrate (for lossy compression only).

type NvPipeCodec

type NvPipeCodec int

NvPipeCodec Available video codecs in NvPipe.

type NvPipeCompression

type NvPipeCompression int

NvPipeCompression Compression type used for encoding.

type NvPipeFormat

type NvPipeFormat int

NvPipeFormat Format of the input frame.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL