Jetson Linux API Reference

38.2 Release
NvVideoEncoder.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2016-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: BSD-3-Clause
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
47 #ifndef __NV_VIDEO_ENCODER_H__
48 #define __NV_VIDEO_ENCODER_H__
49 
50 #include "NvV4l2Element.h"
51 
62 {
63 public:
78  static NvVideoEncoder *createVideoEncoder(const char *name, int flags = 0);
79 
81 
94  int setOutputPlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height,
95  enum v4l2_colorspace cs = V4L2_COLORSPACE_SMPTE170M);
96 
111  int setOutputPlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height,
112  v4l2_colorspace cs, bool extended);
113 
126  int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width,
127  uint32_t height, uint32_t sizeimage);
128 
140  int setFrameRate(uint32_t framerate_num, uint32_t framerate_den);
141 
153  int setBitrate(uint32_t bitrate);
154 
166  int setPeakBitrate(uint32_t peak_bitrate);
167 
180  int setProfile(uint32_t profile);
181 
189  int setEncoderCommand(int cmd, int flags);
190 
203  int setLevel(uint32_t level);
204 
217  int setMaxPerfMode(int flag);
232  int setConstantQp(bool enabled_rc);
233 
247 
259  int setIFrameInterval(uint32_t interval);
260 
272  int setIDRInterval(uint32_t interval);
273 
283  int forceIDR();
284 
298 
312  int setSliceLength(v4l2_enc_slice_length_type type, uint32_t length);
313 
326 
341  int setROIParams(uint32_t buffer_index, v4l2_enc_frame_ROI_params & params);
342 
355 
368 
381 
394 
407 
419  int setH265DisableSAO(bool enabled);
420 
434 
446  int setAV1SsimRdo(bool enabled);
447 
460  int setAV1DisableCDFUpdate(bool disabled);
461 
474  int setAV1ErrResilienceMode(bool enabled);
475 
487  int setAV1FrameIDPresentFlag(bool enabled);
488 
500  int enableAV1TileGroups(bool enabled);
501 
516  int SetInputMetaParams(uint32_t buffer_index, v4l2_ctrl_videoenc_input_metadata &params);
517 
528  int setVirtualBufferSize(uint32_t size);
529 
540  int setNumReferenceFrames(uint32_t num_frames);
541 
552  int setSliceIntrarefresh(uint32_t interval);
553 
565  int setCUDASliceIntrarefresh(uint32_t interval, uint32_t count);
566 
577  int setNumBFrames(uint32_t num);
578 
590  int setInsertSpsPpsAtIdrEnabled(bool enabled);
591 
603  int setCABAC(bool enabled);
604 
616  int setSliceLevelEncode(bool enabled);
617 
628 
644  int getMetadata(uint32_t buffer_index,
646 
662  int getMotionVectors(uint32_t buffer_index,
664 
680  int setQpRange(uint32_t MinQpI, uint32_t MaxQpI, uint32_t MinQpP,
681  uint32_t MaxQpP, uint32_t MinQpB, uint32_t MaxQpB);
682 
695  int setCudaConstantQp(uint32_t qpI, uint32_t qpP,
696  uint32_t qpB);
697 
709  int setSampleAspectRatioWidth(uint32_t sar_width);
710 
722  int setSampleAspectRatioHeight(uint32_t sar_height);
723 
735  int setInsertVuiEnabled(bool enabled);
736 
748  int setExtendedColorFormat(bool enabled);
749 
761  int setInsertAudEnabled(bool enabled);
762 
774  int setAlliFramesEncode(bool enabled);
775 
787  int setPocType(uint32_t pocType);
788 
803  int setInitQP(uint32_t IinitQP, uint32_t PinitQP, uint32_t BinitQP);
804 
816  int setFramesToEncode(uint32_t framesToEncode);
817 
829  int setChromaFactorIDC(uint8_t crfactor);
830 
842  int setLossless(bool enabled);
843 
855  int setDisableAMP(bool enabled);
856 
866  int enableTwoPassCBR();
867 
874  int DevicePoll(v4l2_ctrl_video_device_poll *devicepoll);
875 
880  int SetPollInterrupt();
881 
886  int ClearPollInterrupt();
887 
891  bool isGPUEnabled();
892 
902  int setGPUId(uint32_t gpuId);
903 
913  int setCudaMemType(uint32_t cumemType);
914 
915 private:
919  NvVideoEncoder(const char *name, const char* dev_node, int flags);
920 
921  static const NvElementProfiler::ProfilerField valid_fields =
925 
926  bool gpu_enabled;
927 };
930 #endif
NvVideoEncoder::setChromaFactorIDC
int setChromaFactorIDC(uint8_t crfactor)
Sets the H.265 encoder Chroma Format IDC.
v4l2_enc_enable_roi_param_
Holds the params to configure encoder for ROI parameters encoding.
Definition: v4l2_nv_extensions.h:2683
NvV4l2Element
Defines a helper class for V4L2 based components.
Definition: NvV4l2Element.h:65
NvVideoEncoder::setInsertSpsPpsAtIdrEnabled
int setInsertSpsPpsAtIdrEnabled(bool enabled)
Enables/disables insert SPS PPS at every IDR.
NvVideoEncoder::setAV1SsimRdo
int setAV1SsimRdo(bool enabled)
Enable AV1 variance based SSIM RDO.
v4l2_enc_frame_ROI_params_
Holds the encoder frame ROI parameters to be used with V4L2_CID_MPEG_VIDEOENC_ROI_PARAMS IOCTL.
Definition: v4l2_nv_extensions.h:2307
v4l2_enc_slice_length_type
v4l2_enc_slice_length_type
Enum specifying the type of slice length.
Definition: v4l2_nv_extensions.h:2165
NvVideoEncoder::setROIParams
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 ...
NvVideoEncoder::setInitQP
int setInitQP(uint32_t IinitQP, uint32_t PinitQP, uint32_t BinitQP)
Sets the initial QP for I/P/B frames.
NvVideoEncoder::setInsertAudEnabled
int setInsertAudEnabled(bool enabled)
Enables/disables insert AUD.
NvVideoEncoder::setIFrameInterval
int setIFrameInterval(uint32_t interval)
Sets the encoder I-frame interval.
NvVideoEncoder::setSliceLevelEncode
int setSliceLevelEncode(bool enabled)
Enables/disables Slice level encoding for H264 / HEVC.
NvVideoEncoder::setIDRInterval
int setIDRInterval(uint32_t interval)
Sets the encoder IDR interval.
NvVideoEncoder::enableExternalRC
int enableExternalRC(v4l2_enc_enable_ext_rate_ctr &params)
Enable External Picture RC.
v4l2_ctrl_videoenc_outputbuf_metadata_
Holds the encoder output metadata for a frame, to be used with V4L2_CID_MPEG_VIDEOENC_METADATA IOCTL.
Definition: v4l2_nv_extensions.h:2455
NvVideoEncoder::ClearPollInterrupt
int ClearPollInterrupt()
Clears the polling interrupt, now if the application calls Poll, the device should block until the ev...
NvVideoEncoder::setHWPresetType
int setHWPresetType(v4l2_enc_hw_preset_type type)
Sets the encoder HW Preset Type.
NvElementProfiler::ProfilerField
int ProfilerField
Definition: NvElementProfiler.h:79
NvVideoEncoder::setSliceIntrarefresh
int setSliceIntrarefresh(uint32_t interval)
Sets slice intra-refresh interval params.
NvVideoEncoder::setCudaMemType
int setCudaMemType(uint32_t cumemType)
Sets CUDA Memory type when GPU is enabled.
NvVideoEncoder::setPPEInitParams
int setPPEInitParams(v4l2_enc_ppe_init_params &params)
Sets the preprocessing enhancement (PPE) initialization parameters at the start of the session.
v4l2_enc_temporal_tradeoff_level_type
v4l2_enc_temporal_tradeoff_level_type
Specifies the types of encoder temporal tradeoff levels.
Definition: v4l2_nv_extensions.h:2095
_v4l2_ctrl_video_device_poll
Poll device.
Definition: v4l2_nv_extensions.h:3163
NvVideoEncoder::setPeakBitrate
int setPeakBitrate(uint32_t peak_bitrate)
Sets the encoder peak bitrate.
v4l2_enc_enable_ext_rps_ctrl_
Holds the params to configure encoder for external rps control to be used with V4L2_CID_MPEG_VIDEOENC...
Definition: v4l2_nv_extensions.h:2549
NvVideoEncoder::setConstantQp
int setConstantQp(bool enabled_rc)
Sets constant QP for encoder.
NvVideoEncoder::enableTwoPassCBR
int enableTwoPassCBR()
Sets whether to enable two pass CBR for H.264/H.265.
NvVideoEncoder::SetInputMetaParams
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 buf...
NvVideoEncoder::enableAV1TileGroups
int enableAV1TileGroups(bool enabled)
Enable AV1 frame_id_numbers_present_flag.
v4l2_enc_ppe_init_params_
Holds the preprocessing enhancement initialization parameters to be used with V4L2_CID_MPEG_VIDEOENC_...
Definition: v4l2_nv_extensions.h:2340
NvVideoEncoder::setVirtualBufferSize
int setVirtualBufferSize(uint32_t size)
Sets the virtual buffer size of the encoder.
NvVideoEncoder::setFramesToEncode
int setFramesToEncode(uint32_t framesToEncode)
Sets the number of frames to encode.
NvVideoEncoder::setOutputPlaneFormat
int setOutputPlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height, enum v4l2_colorspace cs=V4L2_COLORSPACE_SMPTE170M)
Sets the format on the encoder output plane.
NvVideoEncoder::enableMotionVectorReporting
int enableMotionVectorReporting()
Enables video encoder output motion vector metadata reporting.
NvVideoEncoder::setEncoderCommand
int setEncoderCommand(int cmd, int flags)
Sets the encoder command.
NvVideoEncoder::enableROI
int enableROI(v4l2_enc_enable_roi_param &params)
Enables External ROI.
NvVideoEncoder::enableExternalRPS
int enableExternalRPS(v4l2_enc_enable_ext_rps_ctr &params)
Enable External RPS.
v4l2_ctrl_videoenc_outputbuf_metadata_MV_
Holds the motion vector parameters for one complete frame.
Definition: v4l2_nv_extensions.h:2379
NvVideoEncoder::setProfile
int setProfile(uint32_t profile)
Sets the encoder profile.
NvVideoEncoder::setSampleAspectRatioWidth
int setSampleAspectRatioWidth(uint32_t sar_width)
Sets Sample Aspect Ratio width for VUI encoding.
NvVideoEncoder::setNumBFrames
int setNumBFrames(uint32_t num)
Sets the number of B frames to P frames.
v4l2_mpeg_video_bitrate_mode
v4l2_mpeg_video_bitrate_mode
Definition: v4l2-controls.h:389
NvVideoEncoder::setLevel
int setLevel(uint32_t level)
Set the encoder level.
NvVideoEncoder::enableReconCRC
int enableReconCRC(v4l2_enc_enable_reconcrc_param &params)
Enables Recon CRC.
NvElementProfiler::PROFILER_FIELD_LATENCIES
static const ProfilerField PROFILER_FIELD_LATENCIES
Definition: NvElementProfiler.h:83
NvVideoEncoder::setQpRange
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.
NvVideoEncoder::DevicePoll
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 o...
NvVideoEncoder::setMaxPerfMode
int setMaxPerfMode(int flag)
Sets the encoder for maximum performance.
NvVideoEncoder::setCapturePlaneFormat
int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height, uint32_t sizeimage)
Sets the format on the converter capture plane.
NvVideoEncoder::setCUDASliceIntrarefresh
int setCUDASliceIntrarefresh(uint32_t interval, uint32_t count)
Sets CUDA slice intra-refresh interval params.
NvVideoEncoder::setSampleAspectRatioHeight
int setSampleAspectRatioHeight(uint32_t sar_height)
Sets Sample Aspect Ratio height for VUI encoding.
NvVideoEncoder::getMotionVectors
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.
NvVideoEncoder::setFrameRate
int setFrameRate(uint32_t framerate_num, uint32_t framerate_den)
Sets the encode framerate.
NvVideoEncoder::setDisableAMP
int setDisableAMP(bool enabled)
Sets the Disable AMP types to true for H.265.
NvVideoEncoder::setAV1ErrResilienceMode
int setAV1ErrResilienceMode(bool enabled)
Enable Error Resilient Mode for AV1.
NvVideoEncoder::setAlliFramesEncode
int setAlliFramesEncode(bool enabled)
Enables/disables all i-frame encode.
NvVideoEncoder::setTemporalTradeoff
int setTemporalTradeoff(v4l2_enc_temporal_tradeoff_level_type level)
Sets the encoder Temporal Tradeoff.
NvVideoEncoder::createVideoEncoder
static NvVideoEncoder * createVideoEncoder(const char *name, int flags=0)
Creates a new V4L2 Video Encoder object named name.
NvVideoEncoder::setH265DisableSAO
int setH265DisableSAO(bool enabled)
Disable SAO filter for HEVC encoding.
NvVideoEncoder::setAV1FrameIDPresentFlag
int setAV1FrameIDPresentFlag(bool enabled)
Enable AV1 frame_id_numbers_present_flag.
NvVideoEncoder::setGPUId
int setGPUId(uint32_t gpuId)
Sets GPU Id when GPU is enabled.
NvVideoEncoder::setExtendedColorFormat
int setExtendedColorFormat(bool enabled)
Enables/disables extended color format.
NvElementProfiler::PROFILER_FIELD_FPS
static const ProfilerField PROFILER_FIELD_FPS
Definition: NvElementProfiler.h:84
NvVideoEncoder::isGPUEnabled
bool isGPUEnabled()
Checks if GPU configuration is enabled to switch to CUDA processing.
NvVideoEncoder::setRateControlMode
int setRateControlMode(enum v4l2_mpeg_video_bitrate_mode mode)
Sets the encoder rate control mode.
NvVideoEncoder::setSliceLength
int setSliceLength(v4l2_enc_slice_length_type type, uint32_t length)
Sets the encoder output slice length.
NvVideoEncoder::enableAV1Tile
int enableAV1Tile(v4l2_enc_av1_tile_config &params)
Enable AV1 Multi-tile configuration.
v4l2_enc_hw_preset_type
v4l2_enc_hw_preset_type
Specifies the encoder HW Preset type.
Definition: v4l2_nv_extensions.h:2113
NvVideoEncoder::setInsertVuiEnabled
int setInsertVuiEnabled(bool enabled)
Enables/disables insert VUI.
NvV4l2Element.h
NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS
static const ProfilerField PROFILER_FIELD_TOTAL_UNITS
Definition: NvElementProfiler.h:81
NvVideoEncoder::SetPollInterrupt
int SetPollInterrupt()
Sets the polling interrupt, now if the application calls Poll, the device should not block,...
v4l2_ctrl_videoenc_input_metadata_
Holds the encoder frame input metadata parameters.
Definition: v4l2_nv_extensions.h:2739
v4l2_enc_av1_tile_config_
Holds the params to configure tiles for AV1 encoding.
Definition: v4l2_nv_extensions.h:2847
NvVideoEncoder::~NvVideoEncoder
~NvVideoEncoder()
NvVideoEncoder::setNumReferenceFrames
int setNumReferenceFrames(uint32_t num_frames)
Sets the number of reference frames of the encoder.
v4l2_enc_enable_ext_rate_ctrl_
Holds the params to configure encoder for external rate control mode to be used with V4L2_CID_MPEG_VI...
Definition: v4l2_nv_extensions.h:2648
NvVideoEncoder::setPocType
int setPocType(uint32_t pocType)
Sets the encoder Picture Order Control type.
v4l2_enc_enable_reconcrc_param_
Holds the params to configure encoder for Reconstructed CRC encoding.
Definition: v4l2_nv_extensions.h:2696
NvVideoEncoder::forceIDR
int forceIDR()
Forces an IDR frame.
NvVideoEncoder::setLossless
int setLossless(bool enabled)
Sets the lossless encoding for H.264/H.265.
NvVideoEncoder::setCudaConstantQp
int setCudaConstantQp(uint32_t qpI, uint32_t qpP, uint32_t qpB)
Sets Const QP values for I/P/B frames.
NvVideoEncoder::setAV1DisableCDFUpdate
int setAV1DisableCDFUpdate(bool disabled)
Disable AV1 CDF update in the symbol decoding process.
NvVideoEncoder::setBitrate
int setBitrate(uint32_t bitrate)
Sets the encoder bitrate.
NvVideoEncoder::getMetadata
int getMetadata(uint32_t buffer_index, v4l2_ctrl_videoenc_outputbuf_metadata &enc_metadata)
Gets metadata for the encoded capture plane buffer.
NvVideoEncoder::setCABAC
int setCABAC(bool enabled)
Enables/disables CABAC entropy encoding for H264.
NvVideoEncoder
Defines a helper class for V4L2 Video Encoder.
Definition: NvVideoEncoder.h:61