Minimize encoded frame delay with NVEncoder

Is it possible to receive the last image as a frame immediately?
Encoded frames are delayed by one frame, the encoder does not return the last image as a frame, but the one before.

Are you referring to the NvEncoder class shipped in the Video Codec SDK? If yes, then this class isn’t directly usable by design, but instead needs to be used through a derived class like NvEncoderCuda. Here’s the constructor for NvEncoderCuda:

NvEncoderCuda(CUcontext cuContext, uint32_t nWidth, uint32_t nHeight, NV_ENC_BUFFER_FORMAT eBufferFormat,
    uint32_t nExtraOutputDelay = 3, bool bMotionEstimationOnly = false, bool bOPInVideoMemory = false);

All these parameters are passed to the base class (NvEncoder) constructor. The parameter out of these relevant to this question is nExtraOutputDelay. It is used as follows, in NvEncoder::CreateEncoder() :

m_nEncoderBuffer = m_encodeConfig.frameIntervalP + m_encodeConfig.rcParams.lookaheadDepth + m_nExtraOutputDelay;
m_nOutputDelay = m_nEncoderBuffer - 1;

frameIntervalP is 1 by default (unless overridden by the preset config, or by the user). lookaheadDepth is 0 for presets P1 - P5. By choosing a value of 0 for the nExtraOutputDelay parameter when creating an object of class NvEncoderCuda or any other derived class, the output delay will be 0. With this, when a frame is provided in the NvEncoder::EncodeFrame() call, the bitstream corresponding to this frame will be available in the output parameters when this call returns.

Note that, while using this path effectively serializes the pipeline, i.e. encode and compute operations will not work in parallel.

Hope this helps.


1 Like

Thank a lot for looking into it, this was the issue one the server side. It is working correctly.
However I had a similar issue on the client side, the decoder was also buffering before rendering the received frames.
I don’t need to make it parallel, I am streaming images which are rerendered only when changed by an interaction.
Thank you very much.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.