Skip to content

Latest commit

 

History

History
62 lines (51 loc) · 1.42 KB

README.md

File metadata and controls

62 lines (51 loc) · 1.42 KB

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.