Jetson Inference
DNN Vision Library

The videoOutput API is for rendering and transmitting frames to video input devices such as display windows, broadcasting RTP network streams to remote hosts over UDP/IP, and saving videos/images/directories to disk. More...

#include <videoOutput.h>

Inheritance diagram for videoOutput:
glDisplay gstEncoder imageWriter

Public Member Functions

virtual ~videoOutput ()
 Destroy interface and release all resources. More...
 
template<typename T >
bool Render (T *image, uint32_t width, uint32_t height)
 Render and output the next frame to the stream. More...
 
virtual bool Render (void *image, uint32_t width, uint32_t height, imageFormat format)
 Render and output the next frame to the stream. More...
 
virtual bool Open ()
 Begin streaming the device. More...
 
virtual void Close ()
 Stop streaming the device. More...
 
bool IsStreaming () const
 Check if the device is actively streaming or not. More...
 
uint32_t GetWidth () const
 Return the width of the stream, in pixels. More...
 
uint32_t GetHeight () const
 Return the height of the stream, in pixels. More...
 
float GetFrameRate () const
 Return the framerate, in Hz or FPS. More...
 
uint64_t GetFrameCount () const
 Return the number of frames output. More...
 
const URIGetResource () const
 Return the resource URI of the stream. More...
 
const videoOptionsGetOptions () const
 Return the videoOptions of the stream. More...
 
void AddOutput (videoOutput *output)
 Add an output sub-stream. More...
 
uint32_t GetNumOutputs () const
 Return the number of sub-streams. More...
 
videoOutputGetOutput (uint32_t index) const
 Return a sub-stream. More...
 
virtual void SetStatus (const char *str)
 Set a status string (i.e. More...
 
virtual uint32_t GetType () const
 Return the interface type of the stream. More...
 
bool IsType (uint32_t type) const
 Check if this stream is of a particular type. More...
 
template<typename T >
bool IsType () const
 Check if a this stream is of a particular type. More...
 
const char * TypeToStr () const
 Convert this stream's class type to string. More...
 

Static Public Member Functions

static videoOutputCreate (const videoOptions &options)
 Create videoOutput interface from a videoOptions struct that's already been filled out. More...
 
static videoOutputCreate (const char *URI, const videoOptions &options=videoOptions())
 Create videoOutput interface from a resource URI string and optional videoOptions. More...
 
static videoOutputCreate (const char *URI, const commandLine &cmdLine)
 Create videoOutput interface from a resource URI string and parsing command line arguments. More...
 
static videoOutputCreate (const char *URI, const int argc, char **argv)
 Create videoOutput interface from a resource URI string and parsing command line arguments. More...
 
static videoOutputCreate (const int argc, char **argv, int positionArg=-1)
 Create videoOutput interface by parsing command line arguments, including the resource URI. More...
 
static videoOutputCreate (const commandLine &cmdLine, int positionArg=-1)
 Create videoOutput interface by parsing command line arguments, including the resource URI. More...
 
static videoOutputCreateNullOutput ()
 Create videoOutput interface that acts as a NULL output and does nothing with incoming frames. More...
 
static const char * Usage ()
 Usage string for command line arguments to Create() More...
 
static const char * TypeToStr (uint32_t type)
 Convert a class type to a string. More...
 

Protected Member Functions

 videoOutput (const videoOptions &options)
 

Protected Attributes

bool mStreaming
 
videoOptions mOptions
 
std::vector< videoOutput * > mOutputs
 

Detailed Description

The videoOutput API is for rendering and transmitting frames to video input devices such as display windows, broadcasting RTP network streams to remote hosts over UDP/IP, and saving videos/images/directories to disk.

videoOutput interfaces are implemented by glDisplay, gstEncoder, and imageWriter.
The specific implementation is selected at runtime based on the type of resource URI. An instance can have multiple sub-streams, for example simultaneously outputting to a display and encoded video on disk or RTP stream.

videoOutput supports the following protocols and resource URI's:

- `display://0` for rendering to display using OpenGL, where `0` corresponds to the display number.
   By default, an OpenGL window will be created, unless the `--headless` command line option is used.

- `rtp://<remote-host>:1234` to broadcast a compressed RTP stream to a remote host, where you should
   substitute `<remote-host>` with the remote host's IP address or hostname, and `1234` is the port.

- `rtsp://@:8554/my_stream` to serve a compressed RTSP stream at the specified port and stream path.
   RTSP clients can connect to the stream at the specified path.  Using this will create a RTSP server
   that can handle multiple videoOutput streams on the same port but with different paths
   (e.g. `rtsp://<hostname>:8554/my_stream_1`, `rtsp://<hostname>:8554/my_stream_2`, ect)

- `webrtc://@:1234/my_stream` to serve a compressed WebRTC stream at the specified port and path
   that browsers can connect to and view.  Users will be able to navigate their browser to
   `http://<hostname>:1234/my_stream` and view a rudimentary video player that plays the stream.
   More advanced web front-ends can be created by using standard client-side Javascript WebRTC APIs.

- `file:///home/user/my_video.mp4` for saving videos, images, and directories of images to disk.
   You can leave off the `file://` protocol identifier and it will be deduced from the path.
   It can be a relative or absolute path.  You can output a sequence of images using a path of
   the form `my_dir/image_%i.jpg` (where `%i` can include printf-style modifiers like `%03i`).  
   The `%i` will be replaced with the image number in the sequence.  If just a directory is
   specified, then by default it will create a sequence of the form `%i.jpg` in that directory.
   Supported video formats for saving include MKV, MP4, AVI, and FLV. Supported codecs for 
   encoding include H.264, H.265, VP8, VP9, and MJPEG. Supported image formats for saving 
   include JPG, PNG, TGA, and BMP.
See also
URI for info about resource URI formats.
videoOptions for additional options and command-line arguments.

Constructor & Destructor Documentation

◆ ~videoOutput()

virtual videoOutput::~videoOutput ( )
virtual

Destroy interface and release all resources.

◆ videoOutput()

videoOutput::videoOutput ( const videoOptions options)
protected

Member Function Documentation

◆ AddOutput()

void videoOutput::AddOutput ( videoOutput output)
inline

Add an output sub-stream.

When a frame is rendered to this stream, it will be rendered to each sub-stream.

◆ Close()

virtual void videoOutput::Close ( )
virtual

Stop streaming the device.

Note
Close() is automatically called by the videoOutput destructor when it gets deleted, so you do not explicitly need to call Close() before exiting the program if you delete your videoSource object.

Reimplemented in gstEncoder.

◆ Create() [1/6]

static videoOutput* videoOutput::Create ( const char *  URI,
const commandLine cmdLine 
)
static

Create videoOutput interface from a resource URI string and parsing command line arguments.

See also
videoOptions for valid command-line arguments to be parsed.
the documentation above and the URI struct for more info about resource URI's.

◆ Create() [2/6]

static videoOutput* videoOutput::Create ( const char *  URI,
const int  argc,
char **  argv 
)
static

Create videoOutput interface from a resource URI string and parsing command line arguments.

See also
videoOptions for valid command-line arguments to be parsed.
the documentation above and the URI struct for more info about resource URI's.

◆ Create() [3/6]

static videoOutput* videoOutput::Create ( const char *  URI,
const videoOptions options = videoOptions() 
)
static

Create videoOutput interface from a resource URI string and optional videoOptions.

See also
the documentation above and the URI struct for more info about resource URI's.

◆ Create() [4/6]

static videoOutput* videoOutput::Create ( const commandLine cmdLine,
int  positionArg = -1 
)
static

Create videoOutput interface by parsing command line arguments, including the resource URI.

Parameters
positionArgindicates the positional argument number in the command line of the resource URI (or -1 if a positional argument isn't used, and should instead be parsed from the --input= option).
See also
videoOptions for valid command-line arguments to be parsed.
the documentation above and the URI struct for more info about resource URI's.

◆ Create() [5/6]

static videoOutput* videoOutput::Create ( const int  argc,
char **  argv,
int  positionArg = -1 
)
static

Create videoOutput interface by parsing command line arguments, including the resource URI.

Parameters
positionArgindicates the positional argument number in the command line of the resource URI (or -1 if a positional argument isn't used, and should instead be parsed from the --input= option).
See also
videoOptions for valid command-line arguments to be parsed.
the documentation above and the URI struct for more info about resource URI's.

◆ Create() [6/6]

static videoOutput* videoOutput::Create ( const videoOptions options)
static

Create videoOutput interface from a videoOptions struct that's already been filled out.

It's expected that the supplied videoOptions already contain a valid resource URI.

◆ CreateNullOutput()

static videoOutput* videoOutput::CreateNullOutput ( )
static

Create videoOutput interface that acts as a NULL output and does nothing with incoming frames.

CreateNullOutput() can be used when there are no other outputs created and programs expect one to run.

◆ GetFrameCount()

uint64_t videoOutput::GetFrameCount ( ) const
inline

Return the number of frames output.

◆ GetFrameRate()

float videoOutput::GetFrameRate ( ) const
inline

Return the framerate, in Hz or FPS.

◆ GetHeight()

uint32_t videoOutput::GetHeight ( ) const
inline

Return the height of the stream, in pixels.

◆ GetNumOutputs()

uint32_t videoOutput::GetNumOutputs ( ) const
inline

Return the number of sub-streams.

◆ GetOptions()

const videoOptions& videoOutput::GetOptions ( ) const
inline

Return the videoOptions of the stream.

◆ GetOutput()

videoOutput* videoOutput::GetOutput ( uint32_t  index) const
inline

Return a sub-stream.

◆ GetResource()

const URI& videoOutput::GetResource ( ) const
inline

Return the resource URI of the stream.

◆ GetType()

virtual uint32_t videoOutput::GetType ( ) const
inlinevirtual

Return the interface type of the stream.

This could be one of the following values:

Reimplemented in glDisplay, gstEncoder, and imageWriter.

◆ GetWidth()

uint32_t videoOutput::GetWidth ( ) const
inline

Return the width of the stream, in pixels.

◆ IsStreaming()

bool videoOutput::IsStreaming ( ) const
inline

Check if the device is actively streaming or not.

Returns
true if the device is streaming (open), or false if it's closed or has reached EOS (End Of Stream).

◆ IsType() [1/2]

template<typename T >
bool videoOutput::IsType ( ) const
inline

Check if a this stream is of a particular type.

Can be used with glDisplay, gstEncoder, and imageWriter. For example:

if( stream->IsType<glDisplay>() ) glDisplay* display = (glDisplay*)stream; // safe to cast

◆ IsType() [2/2]

bool videoOutput::IsType ( uint32_t  type) const
inline

Check if this stream is of a particular type.

See also
GetType() for possible values.

◆ Open()

virtual bool videoOutput::Open ( )
virtual

Begin streaming the device.

After Open() is called, frames from the device can begin to be rendered.

Open() is not stricly necessary to call, if you call one of the Render() functions they will first check to make sure that the stream is opened, and if not they will open it automatically for you.

Returns
true on success, false if an error occurred opening the stream.

Reimplemented in gstEncoder, and glDisplay.

◆ Render() [1/2]

template<typename T >
bool videoOutput::Render ( T *  image,
uint32_t  width,
uint32_t  height 
)
inline

Render and output the next frame to the stream.

The image formats supported by this templated version of Render() include the following:

  • uchar3 (IMAGE_RGB8)
  • uchar4 (IMAGE_RGBA8)
  • float3 (IMAGE_RGB32F)
  • float4 (IMAGE_RGBA32F)

The image format will automatically be deduced from these types. If other types are used with this overload, a static compile-time error will be asserted.

Parameters
imageCUDA pointer containing the image to output.
widthwidth of the image, in pixels.
heightheight of the image, in pixels.
Returns
true on success, false on error.

◆ Render() [2/2]

virtual bool videoOutput::Render ( void *  image,
uint32_t  width,
uint32_t  height,
imageFormat  format 
)
virtual

Render and output the next frame to the stream.

The image formats supported by Render() are IMAGE_RGB8 (uchar3), IMAGE_RGBA8 (uchar4), IMAGE_RGB32F (float3), and IMAGE_RGBA32F (float4).

See also
imageFormat for more info.
Parameters
imageCUDA pointer containing the image to output.
widthwidth of the image, in pixels.
heightheight of the image, in pixels.
formatformat of the image (
See also
imageFormat)
Returns
true on success, false on error.

Reimplemented in glDisplay, gstEncoder, and imageWriter.

◆ SetStatus()

virtual void videoOutput::SetStatus ( const char *  str)
virtual

Set a status string (i.e.

status bar text on display window). Other types of interfaces may ignore the status text.

Reimplemented in glDisplay.

◆ TypeToStr() [1/2]

const char* videoOutput::TypeToStr ( ) const
inline

Convert this stream's class type to string.

◆ TypeToStr() [2/2]

static const char* videoOutput::TypeToStr ( uint32_t  type)
static

Convert a class type to a string.

◆ Usage()

static const char* videoOutput::Usage ( )
inlinestatic

Usage string for command line arguments to Create()

Member Data Documentation

◆ mOptions

videoOptions videoOutput::mOptions
protected

◆ mOutputs

std::vector<videoOutput*> videoOutput::mOutputs
protected

◆ mStreaming

bool videoOutput::mStreaming
protected

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