# Minimize encoded frame delay with NVEncoder

**URL:** <https://forums.developer.nvidia.com/t/minimize-encoded-frame-delay-with-nvencoder/181528>\
**Category:** Video Codec, PyNv & OFA\
**Created:** [June 22, 2021, 1:54pm UTC](https://forums.developer.nvidia.com/t/minimize-encoded-frame-delay-with-nvencoder/181528 "2021-06-22T13:54:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hrvthzs](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@hrvthzs](https://forums.developer.nvidia.com/u/hrvthzs)\
**Post date:** [June 22, 2021, 1:54pm UTC](https://forums.developer.nvidia.com/t/minimize-encoded-frame-delay-with-nvencoder/181528/1 "2021-06-22T13:54:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mandar\_godse](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/mandar_godse/32/14043_2.png) [@mandar\_godse](https://forums.developer.nvidia.com/u/mandar_godse)\
**Post date:** [July 14, 2021, 12:13pm UTC](https://forums.developer.nvidia.com/t/minimize-encoded-frame-delay-with-nvencoder/181528/2 "2021-07-14T12:13:21Z")

</div>

Hi,  
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.

Thanks.

---

<div class="post-metadata">

**Author:** ![hrvthzs](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@hrvthzs](https://forums.developer.nvidia.com/u/hrvthzs)\
**Post date:** [July 15, 2021, 11:08am UTC](https://forums.developer.nvidia.com/t/minimize-encoded-frame-delay-with-nvencoder/181528/3 "2021-07-15T11:08:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [September 13, 2021, 11:08am UTC](https://forums.developer.nvidia.com/t/minimize-encoded-frame-delay-with-nvencoder/181528/4 "2021-09-13T11:08:41Z")

</div>

Closed on September 13, 2021, 11:08am UTC

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