Jetson Linux API Reference

35.2.1 Release
NvVideoEncoder Class Reference

Detailed Description

Defines a helper class for V4L2 Video Encoder.

The video encoder device node is "/dev/nvhost-msenc". The category name for the encoder is "NVENC".

Refer to V4L2 Video Encoder for more information on the encoder.

Definition at line 59 of file NvVideoEncoder.h.

Inheritance diagram for NvVideoEncoder:
Collaboration diagram for NvVideoEncoder:

Public Member Functions

 ~NvVideoEncoder ()
 
int setOutputPlaneFormat (uint32_t pixfmt, uint32_t width, uint32_t height)
 Sets the format on the encoder output plane. More...
 
int setCapturePlaneFormat (uint32_t pixfmt, uint32_t width, uint32_t height, uint32_t sizeimage)
 Sets the format on the converter capture plane. More...
 
int setFrameRate (uint32_t framerate_num, uint32_t framerate_den)
 Sets the encode framerate. More...
 
int setBitrate (uint32_t bitrate)
 Sets the encoder bitrate. More...
 
int setPeakBitrate (uint32_t peak_bitrate)
 Sets the encoder peak bitrate. More...
 
int setProfile (uint32_t profile)
 Sets the encoder profile. More...
 
int setEncoderCommand (int cmd, int flags)
 Sets the encoder command. More...
 
int setLevel (uint32_t level)
 Set the encoder level. More...
 
int setMaxPerfMode (int flag)
 Sets the encoder for maximum performance. More...
 
int setConstantQp (bool enabled_rc)
 Sets constant QP for encoder. More...
 
int setRateControlMode (enum v4l2_mpeg_video_bitrate_mode mode)
 Sets the encoder rate control mode. More...
 
int setIFrameInterval (uint32_t interval)
 Sets the encoder I-frame interval. More...
 
int setIDRInterval (uint32_t interval)
 Sets the encoder IDR interval. More...
 
int forceIDR ()
 Forces an IDR frame. More...
 
int setTemporalTradeoff (v4l2_enc_temporal_tradeoff_level_type level)
 Sets the encoder Temporal Tradeoff. More...
 
int setSliceLength (v4l2_enc_slice_length_type type, uint32_t length)
 Sets the encoder output slice length. More...
 
int setHWPresetType (v4l2_enc_hw_preset_type type)
 Sets the encoder HW Preset Type. More...
 
int setROIParams (uint32_t buffer_index, v4l2_enc_frame_ROI_params &params)
 Sets the Region of Interest (ROI) parameters for the next buffer, which will be queued on the output plane with index buffer_index. More...
 
int setPPEInitParams (v4l2_enc_ppe_init_params &params)
 Sets the preprocessing enhancement (PPE) initialization parameters at the start of the session. More...
 
int enableROI (v4l2_enc_enable_roi_param &params)
 Enables External ROI. More...
 
int enableReconCRC (v4l2_enc_enable_reconcrc_param &params)
 Enables Recon CRC. More...
 
int enableExternalRPS (v4l2_enc_enable_ext_rps_ctr &params)
 Enable External RPS. More...
 
int enableExternalRC (v4l2_enc_enable_ext_rate_ctr &params)
 Enable External Picture RC. More...
 
int enableAV1Tile (v4l2_enc_av1_tile_config &params)
 Enable AV1 Multi-tile configuration. More...
 
int setAV1SsimRdo (bool enabled)
 Enable AV1 variance based SSIM RDO. More...
 
int setAV1DisableCDFUpdate (bool disabled)
 Disable AV1 CDF update in the symbol decoding process. More...
 
int SetInputMetaParams (uint32_t buffer_index, v4l2_ctrl_videoenc_input_metadata &params)
 Set input Metadata parameters for the next buffer which will be queued on output plane with index buffer_index. More...
 
int setVirtualBufferSize (uint32_t size)
 Sets the virtual buffer size of the encoder. More...
 
int setNumReferenceFrames (uint32_t num_frames)
 Sets the number of reference frames of the encoder. More...
 
int setSliceIntrarefresh (uint32_t interval)
 Sets slice intra-refresh interval params. More...
 
int setNumBFrames (uint32_t num)
 Sets the number of B frames to P frames. More...
 
int setInsertSpsPpsAtIdrEnabled (bool enabled)
 Enables/disables insert SPS PPS at every IDR. More...
 
int setCABAC (bool enabled)
 Enables/disables CABAC entropy encoding for H264. More...
 
int setSliceLevelEncode (bool enabled)
 Enables/disables Slice level encoding for H264 / HEVC. More...
 
int enableMotionVectorReporting ()
 Enables video encoder output motion vector metadata reporting. More...
 
int getMetadata (uint32_t buffer_index, v4l2_ctrl_videoenc_outputbuf_metadata &enc_metadata)
 Gets metadata for the encoded capture plane buffer. More...
 
int getMotionVectors (uint32_t buffer_index, v4l2_ctrl_videoenc_outputbuf_metadata_MV &enc_mv_metadata)
 Gets motion vector metadata for the encoded capture plane buffer. More...
 
int setQpRange (uint32_t MinQpI, uint32_t MaxQpI, uint32_t MinQpP, uint32_t MaxQpP, uint32_t MinQpB, uint32_t MaxQpB)
 Sets QP values for I/P/B frames. More...
 
int setSampleAspectRatioWidth (uint32_t sar_width)
 Sets Sample Aspect Ratio width for VUI encoding. More...
 
int setSampleAspectRatioHeight (uint32_t sar_height)
 Sets Sample Aspect Ratio height for VUI encoding. More...
 
int setInsertVuiEnabled (bool enabled)
 Enables/disables insert VUI. More...
 
int setExtendedColorFormat (bool enabled)
 Enables/disables extended color format. More...
 
int setInsertAudEnabled (bool enabled)
 Enables/disables insert AUD. More...
 
int setAlliFramesEncode (bool enabled)
 Enables/disables all i-frame encode. More...
 
int setPocType (uint32_t pocType)
 Sets the encoder Picture Order Control type. More...
 
int setInitQP (uint32_t IinitQP, uint32_t PinitQP, uint32_t BinitQP)
 Sets the initial QP for I/P/B frames. More...
 
int setFramesToEncode (uint32_t framesToEncode)
 Sets the number of frames to encode. More...
 
int setChromaFactorIDC (uint8_t crfactor)
 Sets the H.265 encoder Chroma Format IDC. More...
 
int setLossless (bool enabled)
 Sets the lossless encoding for H.264/H.265. More...
 
int DevicePoll (v4l2_ctrl_video_device_poll *devicepoll)
 Issues Poll on the device which blocks until : a) Either there is something to dequeue from capture or output plane or any events. More...
 
int SetPollInterrupt ()
 Sets the polling interrupt, now if the application calls Poll, the device should not block, in other words polling is disabled. More...
 
int ClearPollInterrupt ()
 Clears the polling interrupt, now if the application calls Poll, the device should block until the event is triggered, in other words polling is enabled. More...
 
int subscribeEvent (uint32_t type, uint32_t id, uint32_t flags)
 Subscribes to an V4L2 event. More...
 
int dqEvent (struct v4l2_event &event, uint32_t max_wait_ms)
 Dequeues an event from the element. More...
 
int setControl (uint32_t id, int32_t value)
 Sets the value of a control. More...
 
int getControl (uint32_t id, int32_t &value)
 Gets the value of a control. More...
 
int setExtControls (struct v4l2_ext_controls &ctl)
 Sets the value of several controls. More...
 
int getExtControls (struct v4l2_ext_controls &ctl)
 Gets the value of several controls. More...
 
virtual int isInError ()
 
int abort ()
 Terminates processing of queued buffers immediately. More...
 
virtual int waitForIdle (uint32_t max_wait_ms)
 Waits until the element processes all the output plane buffers. More...
 
void enableProfiling ()
 Enables profiling for the V4l2Element. More...
 
void getProfilingData (NvElementProfiler::NvElementProfilerData &data)
 Gets profiling data for the element. More...
 
void printProfilingStats (std::ostream &out_stream=std::cout)
 Prints profiling data for the element to an output stream. More...
 
bool isProfilingEnabled ()
 Checks whether profiling is enabled for the element. More...
 

Static Public Member Functions

static NvVideoEncodercreateVideoEncoder (const char *name, int flags=0)
 Creates a new V4L2 Video Encoder object named name. More...
 

Data Fields

NvV4l2ElementPlane output_plane
 Sets the output plane. More...
 
NvV4l2ElementPlane capture_plane
 Sets the capture plane. More...
 
void * app_data
 A pointer to the application-specific data. More...
 

Protected Attributes

int fd
 Specifies the FD of the device opened using v4l2_open. More...
 
uint32_t output_plane_pixfmt
 Pixel format of output plane buffers. More...
 
uint32_t capture_plane_pixfmt
 Pixel format of capture plane buffers. More...
 
int is_in_error
 Indicates if an error was encountered during the operation of the element. More...
 
const char * comp_name
 Specifies the name of the component, for debugging. More...
 
NvElementProfiler profiler
 Profiler for the element. More...
 

Constructor & Destructor Documentation

◆ ~NvVideoEncoder()

NvVideoEncoder::~NvVideoEncoder ( )

Member Function Documentation

◆ abort()

int NvV4l2Element::abort ( )
inherited

Terminates processing of queued buffers immediately.

All the buffers are returned to the application.

Calls VIDIOC_STREAMOFF IOCTL on both of the planes internally.

Returns
0 for success, -1 otherwise.

◆ ClearPollInterrupt()

int NvVideoEncoder::ClearPollInterrupt ( )

Clears the polling interrupt, now if the application calls Poll, the device should block until the event is triggered, in other words polling is enabled.

◆ createVideoEncoder()

static NvVideoEncoder* NvVideoEncoder::createVideoEncoder ( const char *  name,
int  flags = 0 
)
static

Creates a new V4L2 Video Encoder object named name.

This method internally calls v4l2_open on the encoder dev node "/dev/nvhost-msenc" and checks for V4L2_CAP_VIDEO_M2M_MPLANE capability on the device. This method allows the caller to specify additional flags with which the device must be opened.

The device is opened in blocking mode, which can be modified by passing the O_NONBLOCK flag to this method.

Returns
Reference to the newly created encoder object, else NULL in case of failure during initialization.

◆ DevicePoll()

int NvVideoEncoder::DevicePoll ( v4l2_ctrl_video_device_poll devicepoll)

Issues Poll on the device which blocks until : a) Either there is something to dequeue from capture or output plane or any events.

b) Poll was interrupted by a call to the device using V4L2_CID_SET_POLL_INTERRUPT c) Application has already interrupted polling by V4L2_CID_SET_POLL_INTERRUPT

◆ dqEvent()

int NvV4l2Element::dqEvent ( struct v4l2_event &  event,
uint32_t  max_wait_ms 
)
inherited

Dequeues an event from the element.

Calls VIDIOC_DQEVENT IOCTL internally. The caller can specify the maximum time to wait for dequeuing the event. The call blocks until an event is dequeued successfully or timeout is reached.

Parameters
[in,out]eventA reference to the v4l2_event structure to fill.
[in]max_wait_msSpecifies the max wait time for dequeuing an event, in milliseconds.
Returns
0 for success, -1 otherwise.

◆ enableAV1Tile()

int NvVideoEncoder::enableAV1Tile ( v4l2_enc_av1_tile_config params)

Enable AV1 Multi-tile configuration.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_AV1_TILE_CONFIGURATION. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]paramsParameters to be applied, structure of type #v4l2_enc_av1_tile_config
Returns
0 for success, -1 otherwise.

◆ enableExternalRC()

int NvVideoEncoder::enableExternalRC ( v4l2_enc_enable_ext_rate_ctr params)

Enable External Picture RC.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_EXTERNAL_RATE_CONTROL. Must be called after requesting buffer on both the planes.

Parameters
[in]paramsParameters to be applied on the frame, structure of type #v4l2_enc_enable_ext_rate_ctr
Returns
0 for success, -1 otherwise.

◆ enableExternalRPS()

int NvVideoEncoder::enableExternalRPS ( v4l2_enc_enable_ext_rps_ctr params)

Enable External RPS.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_EXTERNAL_RPS_CONTROL. Must be called after requesting buffer on both the planes.

Parameters
[in]paramsParameters to be applied on the frame, structure of type v4l2_enc_enable_ext_rps_ctr
Returns
0 for success, -1 otherwise.

◆ enableMotionVectorReporting()

int NvVideoEncoder::enableMotionVectorReporting ( )

Enables video encoder output motion vector metadata reporting.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_METADATA_MV. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Returns
0 for success, -1 otherwise.

◆ enableProfiling()

void NvV4l2Element::enableProfiling ( )
virtualinherited

Enables profiling for the V4l2Element.

Must be called before setting either plane formats.

Reimplemented from NvElement.

◆ enableReconCRC()

int NvVideoEncoder::enableReconCRC ( v4l2_enc_enable_reconcrc_param params)

Enables Recon CRC.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_RECONCRC_PARAM. Must be called after requesting buffer on both the planes.

Parameters
[in]paramsParameters to be applied on the frame, structure of type v4l2_enc_enable_reconcrc_param.
Returns
0 for success, -1 otherwise.

◆ enableROI()

int NvVideoEncoder::enableROI ( v4l2_enc_enable_roi_param params)

Enables External ROI.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_ROI_PARAM. Must be called after requesting buffer on both the planes.

Parameters
[in]paramsParameters to be applied on the frame, structure of type v4l2_enc_enable_roi_param.
Returns
0 for success, -1 otherwise.

◆ forceIDR()

int NvVideoEncoder::forceIDR ( )

Forces an IDR frame.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE. Must be called after setFormat on both the planes.

Returns
0 for success, -1 otherwise.

◆ getControl()

int NvV4l2Element::getControl ( uint32_t  id,
int32_t &  value 
)
inherited

Gets the value of a control.

Calls VIDIOC_G_CTRL IOCTL internally.

Parameters
[in]idID of the control to get.
[out]valueA reference to the variable into which the control value is read.
Returns
0 for success, -1 otherwise.

◆ getExtControls()

int NvV4l2Element::getExtControls ( struct v4l2_ext_controls &  ctl)
inherited

Gets the value of several controls.

Calls VIDIOC_G_EXT_CTRLS IOCTL internally.

Parameters
[in,out]ctlA pointer to the controls to get.
Returns
0 for success, -1 otherwise.

◆ getMetadata()

int NvVideoEncoder::getMetadata ( uint32_t  buffer_index,
v4l2_ctrl_videoenc_outputbuf_metadata enc_metadata 
)

Gets metadata for the encoded capture plane buffer.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_METADATA. Must be called for a buffer that has been dequeued from the capture plane. The returned metadata corresponds to the last dequeued buffer with index buffer_index.

Parameters
[in]buffer_indexIndex of the capture plane buffer whose metadata is required.
[in,out]enc_metadataReference to the metadata structure v4l2_ctrl_videoenc_outputbuf_metadata to be filled.
Returns
0 for success, -1 otherwise.

◆ getMotionVectors()

int NvVideoEncoder::getMotionVectors ( uint32_t  buffer_index,
v4l2_ctrl_videoenc_outputbuf_metadata_MV enc_mv_metadata 
)

Gets motion vector metadata for the encoded capture plane buffer.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_METADATA_MV. Must be called for a buffer that has been dequeued from the capture plane. The returned metadata corresponds to the last dequeued buffer with index buffer_index.

Parameters
[in]buffer_indexIndex of the capture plane buffer whose metadata is required.
[in,out]enc_mv_metadataReference to the metadata structure v4l2_ctrl_videoenc_outputbuf_metadata_MV to be filled.
Returns
0 for success, -1 otherwise.

◆ getProfilingData()

void NvElement::getProfilingData ( NvElementProfiler::NvElementProfilerData data)
inherited

Gets profiling data for the element.

Returns
A constant reference to the element's profiling data.

◆ isInError()

virtual int NvV4l2Element::isInError ( )
virtualinherited

Reimplemented from NvElement.

◆ isProfilingEnabled()

bool NvElement::isProfilingEnabled ( )
inherited

Checks whether profiling is enabled for the element.

Returns
Boolean value indicating if profiling is enabled.

◆ printProfilingStats()

void NvElement::printProfilingStats ( std::ostream &  out_stream = std::cout)
inherited

Prints profiling data for the element to an output stream.

Parameters
[in]out_streamOutput stream of type std::ostream to print the data to. It takes the default value std::cout if not specified.

◆ setAlliFramesEncode()

int NvVideoEncoder::setAlliFramesEncode ( bool  enabled)

Enables/disables all i-frame encode.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_ALLIFRAME_ENCODE. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setAV1DisableCDFUpdate()

int NvVideoEncoder::setAV1DisableCDFUpdate ( bool  disabled)

Disable AV1 CDF update in the symbol decoding process.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_AV1_DISABLE_CDF_UPDATE. The value true disables the CDF update. Must be called after setFormat on both the planes.

Parameters
[in]disabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setAV1SsimRdo()

int NvVideoEncoder::setAV1SsimRdo ( bool  enabled)

Enable AV1 variance based SSIM RDO.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_AV1_ENABLE_SSIMRDO. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setBitrate()

int NvVideoEncoder::setBitrate ( uint32_t  bitrate)

Sets the encoder bitrate.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_BITRATE. Can be called any time after setFormat on both the planes.

Parameters
[in]bitrateBitrate of the encoded stream, in bits per second.
Returns
0 for success, -1 otherwise.

◆ setCABAC()

int NvVideoEncoder::setCABAC ( bool  enabled)

Enables/disables CABAC entropy encoding for H264.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setCapturePlaneFormat()

int NvVideoEncoder::setCapturePlaneFormat ( uint32_t  pixfmt,
uint32_t  width,
uint32_t  height,
uint32_t  sizeimage 
)

Sets the format on the converter capture plane.

Calls VIDIOC_S_FMT IOCTL internally on the capture plane.

Parameters
[in]pixfmtOne of the coded V4L2 pixel formats.
[in]widthWidth of the input buffers in pixels.
[in]heightHeight of the input buffers in pixels.
[in]sizeimageMaximum size of the encoded buffers on the capture. plane in bytes
Returns
0 for success, -1 otherwise.

◆ setChromaFactorIDC()

int NvVideoEncoder::setChromaFactorIDC ( uint8_t  crfactor)

Sets the H.265 encoder Chroma Format IDC.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_H265_CHROMA_FACTOR_IDC. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]crfactorSet chroma_factor_idc for the encoder.
Returns
0 for success, -1 otherwise.

◆ setConstantQp()

int NvVideoEncoder::setConstantQp ( bool  enabled_rc)

Sets constant QP for encoder.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE to enable/disable rate control. If the value false is given, it disables RC and set constant QP parameters. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]enabled_rcBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setControl()

int NvV4l2Element::setControl ( uint32_t  id,
int32_t  value 
)
inherited

Sets the value of a control.

Calls VIDIOC_S_CTRL IOCTL internally.

Parameters
[in]idID of the control to be set.
[in]valueValue to be set on the control.
Returns
0 for success, -1 otherwise.

◆ setEncoderCommand()

int NvVideoEncoder::setEncoderCommand ( int  cmd,
int  flags 
)

Sets the encoder command.

Calls the VIDIOC_ENCODER_CMD internally with encoder commands.

Returns
0 for succes, -1 otherwise.

◆ setExtControls()

int NvV4l2Element::setExtControls ( struct v4l2_ext_controls &  ctl)
inherited

Sets the value of several controls.

Calls VIDIOC_S_EXT_CTRLS IOCTL internally.

Parameters
[in]ctlA pointer to the controls to set.
Returns
0 for success, -1 otherwise.

◆ setExtendedColorFormat()

int NvVideoEncoder::setExtendedColorFormat ( bool  enabled)

Enables/disables extended color format.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_EXTEDED_COLORFORMAT. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setFrameRate()

int NvVideoEncoder::setFrameRate ( uint32_t  framerate_num,
uint32_t  framerate_den 
)

Sets the encode framerate.

Calls the VIDIOC_S_PARM IOCTL on the encoder capture plane. Can be called any time after setFormat on both the planes.

Parameters
[in]framerate_numNumerator part of the framerate fraction.
[in]framerate_denDenominator part of the framerate fraction.
Returns
0 for success, -1 otherwise.

◆ setFramesToEncode()

int NvVideoEncoder::setFramesToEncode ( uint32_t  framesToEncode)

Sets the number of frames to encode.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID #V4L2_CID_MPEG_VIDEO_FRAMES_TO_ENCODE. Must be called after setFormat on both the planes.

Parameters
[in]framesToEncodeSet the number of frames to encode.
Returns
0 for success, -1 otherwise.

◆ setHWPresetType()

int NvVideoEncoder::setHWPresetType ( v4l2_enc_hw_preset_type  type)

Sets the encoder HW Preset Type.

Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control ID V4L2_CID_MPEG_VIDEOENC_HW_PRESET_TYPE_PARAM. Must be called after setFormat() on both the planes and before requestBuffers on any of the planes.

Parameters
[in]typeHW Preset Type, one of enum v4l2_enc_hw_preset_type_param.
Returns
0 for success, -1 otherwise.

◆ setIDRInterval()

int NvVideoEncoder::setIDRInterval ( uint32_t  interval)

Sets the encoder IDR interval.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_IDR_INTERVAL. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]intervalInterval between two IDR frames, in number of frames.
Returns
0 for success, -1 otherwise.

◆ setIFrameInterval()

int NvVideoEncoder::setIFrameInterval ( uint32_t  interval)

Sets the encoder I-frame interval.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_GOP_SIZE. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]intervalInterval between two I frames, in number of frames.
Returns
0 for success, -1 otherwise.

◆ setInitQP()

int NvVideoEncoder::setInitQP ( uint32_t  IinitQP,
uint32_t  PinitQP,
uint32_t  BinitQP 
)

Sets the initial QP for I/P/B frames.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id V4L2_CID_MPEG_VIDEOENC_INIT_FRAME_QP. Must be called after setFormat on both the planes.

Parameters
[in]IinitQPQp Value for I frame.
[in]PinitQPQp Value for P frame.
[in]BinitQPQp Value for B frame.
Returns
0 for success, -1 otherwise.

◆ SetInputMetaParams()

int NvVideoEncoder::SetInputMetaParams ( uint32_t  buffer_index,
v4l2_ctrl_videoenc_input_metadata params 
)

Set input Metadata parameters for the next buffer which will be queued on output plane with index buffer_index.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_INPUT_METADATA. Must be called after requesting buffer on both the planes.

Parameters
[in]buffer_indexIndex of output plane buffer on which the external RC params should be applied.
[in]paramsParameters to be applied on the frame, structure of type v4l2_ctrl_videoenc_input_metadata
Returns
0 for success, -1 otherwise.

◆ setInsertAudEnabled()

int NvVideoEncoder::setInsertAudEnabled ( bool  enabled)

Enables/disables insert AUD.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_H264_AUD_SAR_ENABLE. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setInsertSpsPpsAtIdrEnabled()

int NvVideoEncoder::setInsertSpsPpsAtIdrEnabled ( bool  enabled)

Enables/disables insert SPS PPS at every IDR.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_INSERT_SPS_PPS_AT_IDR. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setInsertVuiEnabled()

int NvVideoEncoder::setInsertVuiEnabled ( bool  enabled)

Enables/disables insert VUI.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_INSERT_VUI. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setLevel()

int NvVideoEncoder::setLevel ( uint32_t  level)

Set the encoder level.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_H264_LEVEL or V4L2_CID_MPEG_VIDEOENC_H265_LEVEL, depending on encoder type. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]levelLevel to be used for encoding
Returns
0 for success, -1 otherwise.

◆ setLossless()

int NvVideoEncoder::setLossless ( bool  enabled)

Sets the lossless encoding for H.264/H.265.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_LOSSLESS. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]enabledIndicates whether to enable or disable the control.
Returns
0 for success, -1 otherwise.

◆ setMaxPerfMode()

int NvVideoEncoder::setMaxPerfMode ( int  flag)

Sets the encoder for maximum performance.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_MAX_PERFORMANCE. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]flagInteger variable to indicate whether max performance is to be enabled/disabled.
Returns
0 for success, -1 otherwise.

◆ setNumBFrames()

int NvVideoEncoder::setNumBFrames ( uint32_t  num)

Sets the number of B frames to P frames.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_NUM_BFRAMES. Must be called after setFormat on both the planes.

Parameters
[in]numNumber of B frames.
Returns
0 for success, -1 otherwise.

◆ setNumReferenceFrames()

int NvVideoEncoder::setNumReferenceFrames ( uint32_t  num_frames)

Sets the number of reference frames of the encoder.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_NUM_REFERENCE_FRAMES. Must be called after setFormat on both the planes.

Parameters
[in]num_framesNumber of reference frames.
Returns
0 for success, -1 otherwise.

◆ setOutputPlaneFormat()

int NvVideoEncoder::setOutputPlaneFormat ( uint32_t  pixfmt,
uint32_t  width,
uint32_t  height 
)

Sets the format on the encoder output plane.

Calls VIDIOC_S_FMT IOCTL internally on the output plane.

Precondition
Applications must set the capture plane format using setCapturePlaneFormat before calling this method.
Parameters
[in]pixfmtOne of the raw V4L2 pixel formats.
[in]widthWidth of the input buffers in pixels.
[in]heightHeight of the input buffers in pixels.
Returns
0 for success, -1 otherwise.

◆ setPeakBitrate()

int NvVideoEncoder::setPeakBitrate ( uint32_t  peak_bitrate)

Sets the encoder peak bitrate.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_BITRATE_PEAK. Can be called any time after setFormat on both the planes. Takes effect in VBR mode

Parameters
[in]peak_bitratePeak Bitrate of the encoded stream, in bits per second.
Returns
0 for success, -1 otherwise.

◆ setPocType()

int NvVideoEncoder::setPocType ( uint32_t  pocType)

Sets the encoder Picture Order Control type.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_POC_TYPE. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]pocTypeSet the Picture Order Count for the encoder.
Returns
0 for success, -1 otherwise.

◆ SetPollInterrupt()

int NvVideoEncoder::SetPollInterrupt ( )

Sets the polling interrupt, now if the application calls Poll, the device should not block, in other words polling is disabled.

◆ setPPEInitParams()

int NvVideoEncoder::setPPEInitParams ( v4l2_enc_ppe_init_params params)

Sets the preprocessing enhancement (PPE) initialization parameters at the start of the session.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_PPE_INIT_PARAMS. Must be called after requesting buffer on both the planes.

Parameters
[in]paramsA reference to the parameters to be applied on the frame, structure of type v4l2_enc_ppe_init_params.
Returns
0 for success, -1 otherwise.

◆ setProfile()

int NvVideoEncoder::setProfile ( uint32_t  profile)

Sets the encoder profile.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_H264_PROFILE or V4L2_CID_MPEG_VIDEO_H265_PROFILE, depending on the encoder type. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]profileProfile to be used for encoding.
Returns
0 for success, -1 otherwise.

◆ setQpRange()

int NvVideoEncoder::setQpRange ( uint32_t  MinQpI,
uint32_t  MaxQpI,
uint32_t  MinQpP,
uint32_t  MaxQpP,
uint32_t  MinQpB,
uint32_t  MaxQpB 
)

Sets QP values for I/P/B frames.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id V4L2_CID_MPEG_VIDEOENC_QP_RANGE. Must be called after setFormat on both the planes.

Parameters
[in]MinQpIMinimum Qp Value for I frame.
[in]MaxQpIMinimum Qp Value for I frame.
[in]MinQpPMinimum Qp Value for P frame.
[in]MaxQpPMinimum Qp Value for P frame.
[in]MinQpBMinimum Qp Value for B frame.
[in]MaxQpBMinimum Qp Value for B frame.
Returns
0 for success, -1 otherwise.

◆ setRateControlMode()

int NvVideoEncoder::setRateControlMode ( enum v4l2_mpeg_video_bitrate_mode  mode)

Sets the encoder rate control mode.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEO_BITRATE_MODE. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]modeType of rate control, one of enum v4l2_mpeg_video_bitrate_mode.
Returns
0 for success, -1 otherwise.

◆ setROIParams()

int NvVideoEncoder::setROIParams ( uint32_t  buffer_index,
v4l2_enc_frame_ROI_params params 
)

Sets the Region of Interest (ROI) parameters for the next buffer, which will be queued on the output plane with index buffer_index.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ROI_PARAMS. Must be called after requesting buffer on both the planes.

Parameters
[in]buffer_indexIndex of the output plane buffer to apply the ROI params.
[in]paramsA reference to the parameters to be applied on the frame, structure of type v4l2_enc_frame_ROI_params.
Returns
0 for success, -1 otherwise.

◆ setSampleAspectRatioHeight()

int NvVideoEncoder::setSampleAspectRatioHeight ( uint32_t  sar_height)

Sets Sample Aspect Ratio height for VUI encoding.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT or V4L2_CID_MPEG_VIDEOENC_H265_VUI_EXT_SAR_HEIGHT, depending on the encoder type. Must be called after setFormat on both the planes.

Parameters
[in]sar_heightSAR for height.
Returns
0 for success, -1 otherwise.

◆ setSampleAspectRatioWidth()

int NvVideoEncoder::setSampleAspectRatioWidth ( uint32_t  sar_width)

Sets Sample Aspect Ratio width for VUI encoding.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH or V4L2_CID_MPEG_VIDEOENC_H265_VUI_EXT_SAR_WIDTH, depending on the encoder type. Must be called after setFormat on both the planes.

Parameters
[in]sar_widthSAR for width.
Returns
0 for success, -1 otherwise.

◆ setSliceIntrarefresh()

int NvVideoEncoder::setSliceIntrarefresh ( uint32_t  interval)

Sets slice intra-refresh interval params.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_SLICE_INTRAREFRESH_PARAM. Must be called after setFormat on both the planes.

Parameters
[in]intervalSlice intra-refresh interval, in number of slices.
Returns
0 for success, -1 otherwise.

◆ setSliceLength()

int NvVideoEncoder::setSliceLength ( v4l2_enc_slice_length_type  type,
uint32_t  length 
)

Sets the encoder output slice length.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_SLICE_LENGTH_PARAM. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]typeSlice length type, one of enum v4l2_enc_slice_length_type.
[in]lengthLength of the slice, in bytes if the type is V4L2_ENC_SLICE_LENGTH_TYPE_BITS, else in number of MBs if the type is V4L2_ENC_SLICE_LENGTH_TYPE_MBLK.
Returns
0 for success, -1 otherwise.

◆ setSliceLevelEncode()

int NvVideoEncoder::setSliceLevelEncode ( bool  enabled)

Enables/disables Slice level encoding for H264 / HEVC.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_ENABLE_SLICE_LEVEL_ENCODE. Must be called after setFormat on both the planes.

Parameters
[in]enabledBoolean value indicating whether to enable/disable the control.
Returns
0 for success, -1 otherwise.

◆ setTemporalTradeoff()

int NvVideoEncoder::setTemporalTradeoff ( v4l2_enc_temporal_tradeoff_level_type  level)

Sets the encoder Temporal Tradeoff.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_TEMPORAL_TRADEOFF_LEVEL. Must be called after setFormat on both the planes and before requestBuffers on any of the planes.

Parameters
[in]levelTemporal tradeoff level, one of v4l2_enc_temporal_tradeoff_level_type.
Returns
0 for success, -1 otherwise.

◆ setVirtualBufferSize()

int NvVideoEncoder::setVirtualBufferSize ( uint32_t  size)

Sets the virtual buffer size of the encoder.

Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID V4L2_CID_MPEG_VIDEOENC_VIRTUALBUFFER_SIZE. Must be called after setFormat on both the planes.

Parameters
[in]sizeVirtual buffer size, in bytes.
Returns
0 for success, -1 otherwise.

◆ subscribeEvent()

int NvV4l2Element::subscribeEvent ( uint32_t  type,
uint32_t  id,
uint32_t  flags 
)
inherited

Subscribes to an V4L2 event.

Calls VIDIOC_SUBSCRIBE_EVENT IOCTL internally.

Parameters
[in]typeType of the event.
[in]idID of the event source.
[in]flagsEvent flags.
Returns
0 for success, -1 otherwise.

◆ waitForIdle()

virtual int NvV4l2Element::waitForIdle ( uint32_t  max_wait_ms)
virtualinherited

Waits until the element processes all the output plane buffers.

Objects extending V4l2Element must implement this because the idle condition is component-specific.

Parameters
[in]max_wait_msMax time to wait in milliseconds.
Returns
0 for success, -1 otherwise.

Reimplemented in NvVideoConverter.

Field Documentation

◆ app_data

void* NvV4l2Element::app_data
inherited

A pointer to the application-specific data.

Definition at line 169 of file NvV4l2Element.h.

◆ capture_plane

NvV4l2ElementPlane NvV4l2Element::capture_plane
inherited

Sets the capture plane.

Capture plane of the element

Definition at line 145 of file NvV4l2Element.h.

◆ capture_plane_pixfmt

uint32_t NvV4l2Element::capture_plane_pixfmt
protectedinherited

Pixel format of capture plane buffers.

Definition at line 182 of file NvV4l2Element.h.

◆ comp_name

const char* NvElement::comp_name
protectedinherited

Specifies the name of the component, for debugging.

Definition at line 122 of file NvElement.h.

◆ fd

int NvV4l2Element::fd
protectedinherited

Specifies the FD of the device opened using v4l2_open.

Definition at line 179 of file NvV4l2Element.h.

◆ is_in_error

int NvElement::is_in_error
protectedinherited

Indicates if an error was encountered during the operation of the element.

Definition at line 120 of file NvElement.h.

Referenced by NvElement::isInError().

◆ output_plane

NvV4l2ElementPlane NvV4l2Element::output_plane
inherited

Sets the output plane.

Output plane of the element

Definition at line 141 of file NvV4l2Element.h.

◆ output_plane_pixfmt

uint32_t NvV4l2Element::output_plane_pixfmt
protectedinherited

Pixel format of output plane buffers.

Definition at line 181 of file NvV4l2Element.h.

◆ profiler

NvElementProfiler NvElement::profiler
protectedinherited

Profiler for the element.

Definition at line 124 of file NvElement.h.


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