Failed to open nvenc codec

My laptop has two GPUs, an integrated intel GPU and a dedicated Nvidia GPU, which provides support for external monitors.

I have been facing a video card related issue for a while, but never bothered to check for a solution since a simple restart always solves it. I use OBS studio and Kdenlive for recording and video editing. To make things faster, I use the nvec codec, which uses the Nvidia GPU. This works fine, except that sometimes after my laptop hasn’t been rebooted for a couple of days, I get “failed to open nvec codec” when trying to record my screen, for example. Kdenlive also fails to use the nvec codec to export files. I thought at first that maybe the nvidia drivers have crashed, but my external monitors, which are connected to the GPU, are running. So, the problem is likely somewhre else. The only way I know of resolving this issue at the moment is through a system restart. I wonder if there’s a way to fix this issue without restarting the system as I sometimes have a lot of things running.

a problem with the suspend/power-management ? sounds to me that it might be the cause of the trouble

Does this behavior occur even without installing any updates?

In other words, if you don’t update your system (not even a single package), will it continue to operate normally with the nvenc encoder?

I was just trying to make the point that I only experience the issue after my laptop has been up for days.

Yes. I sometimes go a month without updating my system.

Does this occur with vanilla ffmpeg?

For example,

ffmpeg -i original.mp4 -vcodec h264_nvenc new.mp4

To be clear, when you receive the error message in OBS or Kdenlive, do you get the same error message when you try to encode a sample video with fmpeg before rebooting?

I’ve never tried encoding a video when I get the error. But I would expect to get the same error since kdenlive is probably doing something similar to the code snippet your provided.

It would be good to rule it out, since if ffmpeg continues to work using the h264_nvenc encoder, then it hints to an issue higher up (such as Kdenlive and OBS, or something shared between the two.)

If ffmpeg fails, then it points to a more lower-level issue (hardware? driver?), and perhaps an issue interrelated to ffmpeg itself, since it’s usually used as a backend for other software. (It could even be an issue with FFmpeg version 4 vs version 5).

The issue seems to go after a restart. Is there something I can do to avoid restarting the system?