How to release memory in graphic cards?

I am using NVIDIA Quadro P620.

I have used ffmpeg to transcode with my GPU several times using the command

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.avi -c:v h264_nvenc output.mp4

Then ffmpeg stops transcoding and telling me off:

No decoder surfaces left

It seems the GPU memory got filled up and not released. If I remove -hwaccel_output_format cuda option, transcoding works again.

How do I flush GPU memory? How do I manage GPU memory in windows 10?


This seems like a known bug:
#7562 open defect using -hwaccel nvdec produces 'No decoder surfaces left' with interlaced input and 3 or more b-frames.

The proposed workarounds in this post were:

  • Add the parameter -extra_hw_frames 3
  • Use the filter scale_cuda or yadif_cuda.