Jetson Inference
DNN Vision Library
gstEncoder Class Reference

Hardware-accelerated H.264/H.265 video encoder for Jetson using GStreamer. More...

#include <gstEncoder.h>

Public Member Functions

 ~gstEncoder ()
 Destructor. More...
 
bool EncodeRGBA (uint8_t *buffer)
 Encode the next fixed-point RGBA frame. More...
 
bool EncodeRGBA (float *buffer, float maxPixelValue=255.0f)
 Encode the next floating-point RGBA frame. More...
 
bool EncodeI420 (void *buffer, size_t size)
 Encode the next I420 frame provided by the user. More...
 
uint32_t GetWidth () const
 Retrieve the width that the encoder was created for, in pixels. More...
 
uint32_t GetHeight () const
 Retrieve the height that the encoder was created for, in pixels. More...
 

Static Public Member Functions

static gstEncoderCreate (gstCodec codec, uint32_t width, uint32_t height, const char *filename)
 Create an encoder instance that outputs to a file on disk. More...
 
static gstEncoderCreate (gstCodec codec, uint32_t width, uint32_t height, const char *ipAddress, uint16_t port)
 Create an encoder instance that streams over the network. More...
 
static gstEncoderCreate (gstCodec codec, uint32_t width, uint32_t height, const char *filename, const char *ipAddress, uint16_t port)
 Create an encoder instance that outputs to a file on disk and streams over the network. More...
 

Protected Member Functions

 gstEncoder ()
 
bool buildCapsStr ()
 
bool buildLaunchStr ()
 
bool init (gstCodec codec, uint32_t width, uint32_t height, const char *filename, const char *ipAddress, uint16_t port)
 

Static Protected Member Functions

static void onNeedData (_GstElement *pipeline, uint32_t size, void *user_data)
 
static void onEnoughData (_GstElement *pipeline, void *user_data)
 

Protected Attributes

_GstBus * mBus
 
_GstCaps * mBufferCaps
 
_GstElement * mAppSrc
 
_GstElement * mPipeline
 
gstCodec mCodec
 
bool mNeedData
 
uint32_t mWidth
 
uint32_t mHeight
 
std::string mCapsStr
 
std::string mLaunchStr
 
std::string mOutputPath
 
std::string mOutputIP
 
uint16_t mOutputPort
 
void * mCpuRGBA
 
void * mGpuRGBA
 
void * mCpuI420
 
void * mGpuI420
 

Detailed Description

Hardware-accelerated H.264/H.265 video encoder for Jetson using GStreamer.

The encoder can write the encoded video to disk in .mkv or .h264/.h265 formats, or handle streaming network transmission to remote host(s) via RTP/RTSP protocol.

Constructor & Destructor Documentation

◆ ~gstEncoder()

gstEncoder::~gstEncoder ( )

Destructor.

◆ gstEncoder()

gstEncoder::gstEncoder ( )
protected

Member Function Documentation

◆ buildCapsStr()

bool gstEncoder::buildCapsStr ( )
protected

◆ buildLaunchStr()

bool gstEncoder::buildLaunchStr ( )
protected

◆ Create() [1/3]

static gstEncoder* gstEncoder::Create ( gstCodec  codec,
uint32_t  width,
uint32_t  height,
const char *  filename 
)
static

Create an encoder instance that outputs to a file on disk.

◆ Create() [2/3]

static gstEncoder* gstEncoder::Create ( gstCodec  codec,
uint32_t  width,
uint32_t  height,
const char *  ipAddress,
uint16_t  port 
)
static

Create an encoder instance that streams over the network.

◆ Create() [3/3]

static gstEncoder* gstEncoder::Create ( gstCodec  codec,
uint32_t  width,
uint32_t  height,
const char *  filename,
const char *  ipAddress,
uint16_t  port 
)
static

Create an encoder instance that outputs to a file on disk and streams over the network.

◆ EncodeI420()

bool gstEncoder::EncodeI420 ( void *  buffer,
size_t  size 
)

Encode the next I420 frame provided by the user.

Expects 12-bpp (bit per pixel) image in YUV I420 format. This image is passed to GStreamer, so CPU pointer should be used.

Parameters
bufferCPU pointer to the I420 image

◆ EncodeRGBA() [1/2]

bool gstEncoder::EncodeRGBA ( uint8_t *  buffer)

Encode the next fixed-point RGBA frame.

Expects 8-bit per channel, 32-bit per pixel unsigned image, range 0-255. It is assumed the width of the buffer is equal to GetWidth(), and that the height of the buffer is equal to GetHeight(). This function performs colorspace conversion using CUDA, so the buffer pointer is expected to be CUDA memory allocated on the GPU.

Parameters
bufferCUDA pointer to the RGBA image.

◆ EncodeRGBA() [2/2]

bool gstEncoder::EncodeRGBA ( float *  buffer,
float  maxPixelValue = 255.0f 
)

Encode the next floating-point RGBA frame.

It is assumed the width of the buffer is equal to GetWidth(), and that the height of the buffer is equal to GetHeight(). This function performs colorspace conversion using CUDA, so the buffer pointer is expected to be CUDA memory allocated on the GPU.

Parameters
bufferCUDA pointer to the RGBA image.
maxPixelValueindicates the maximum pixel intensity (typically 255.0f or 1.0f)

◆ GetHeight()

uint32_t gstEncoder::GetHeight ( ) const
inline

Retrieve the height that the encoder was created for, in pixels.

◆ GetWidth()

uint32_t gstEncoder::GetWidth ( ) const
inline

Retrieve the width that the encoder was created for, in pixels.

◆ init()

bool gstEncoder::init ( gstCodec  codec,
uint32_t  width,
uint32_t  height,
const char *  filename,
const char *  ipAddress,
uint16_t  port 
)
protected

◆ onEnoughData()

static void gstEncoder::onEnoughData ( _GstElement *  pipeline,
void *  user_data 
)
staticprotected

◆ onNeedData()

static void gstEncoder::onNeedData ( _GstElement *  pipeline,
uint32_t  size,
void *  user_data 
)
staticprotected

Member Data Documentation

◆ mAppSrc

_GstElement* gstEncoder::mAppSrc
protected

◆ mBufferCaps

_GstCaps* gstEncoder::mBufferCaps
protected

◆ mBus

_GstBus* gstEncoder::mBus
protected

◆ mCapsStr

std::string gstEncoder::mCapsStr
protected

◆ mCodec

gstCodec gstEncoder::mCodec
protected

◆ mCpuI420

void* gstEncoder::mCpuI420
protected

◆ mCpuRGBA

void* gstEncoder::mCpuRGBA
protected

◆ mGpuI420

void* gstEncoder::mGpuI420
protected

◆ mGpuRGBA

void* gstEncoder::mGpuRGBA
protected

◆ mHeight

uint32_t gstEncoder::mHeight
protected

◆ mLaunchStr

std::string gstEncoder::mLaunchStr
protected

◆ mNeedData

bool gstEncoder::mNeedData
protected

◆ mOutputIP

std::string gstEncoder::mOutputIP
protected

◆ mOutputPath

std::string gstEncoder::mOutputPath
protected

◆ mOutputPort

uint16_t gstEncoder::mOutputPort
protected

◆ mPipeline

_GstElement* gstEncoder::mPipeline
protected

◆ mWidth

uint32_t gstEncoder::mWidth
protected

The documentation for this class was generated from the following file: