Resetting the NvVideoEncoder

When using the NvVideoEncoder, I noticed that creating and setting up it use some significant time and resource. I wonder if it is possible to reset an encoder so that it can be used to encode into a new file without recreating it.

More specifically, what we want here is : encoding video into a new file every 1 mins, so we can use each encoded file separately. To do that, i want to be able to, every one minute, dequeue all finished buffers, write them and finish the previous file, then reset the encoder and start writing it results to a new file.

Thanks

May I know what’s the Jetson platform your’re using?

We are using the agx. Jetpack 4.5.

This is similar to question:

and

but those are not answered either

Hi,
We suggest split at SPS/PPS/IDR frames instead of terminating NvVideoEncoder. Please refer to this patch:
Xavier AGX : Video encoding crash - #15 by DaneLLL

Thanks, that should work. I assume it also work for h265.
The problem very related to this is: what does forceIDR actually do? does it affect the frame being enqueued to the output_plane or the frame being encoded at the moment?

Hi,
By setting IDR interval IDR frames are encoded in fixed period. If forceIDR is send in runtime, it encodes IDR frames immediately. For example if we set IDR interval = 30, and send forceIDR at ~ 17th frames, it encodes the 17th frame into IDR frame(may have 2-3 frame delay at 19th or 20th).

Do i need to call forceIDR before or after I enqueue the v4l2_buf to make that buf IDR? or it actually does that to the one being encoded(which can be any one in the buffer)?

Hi,
It should not be required to set forceIDR in the use-case. For splitting at 1 minute, if your source is at 30 fps and you set IDR interval = 30, you should split in receiving 1800 frames. The 1st, 1801th, 3601th… frames are IDR frames.