Help with ffmpeg hardware accelaration on Linux

I am using an NVidia GTX 1050 as a GPU on my computer running Debian 10. I followed this guide to get the drivers installed :

* Cuda installation guide on Linux

Using the package manager method

Also I compiled ffmpeg using this guide :

* FFMpeg with NVidia gpu guide

Following are the logs from :

  1. nvidia-smi command
Fri Apr  8 12:21:42 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.103.01   Driver Version: 470.103.01   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| 44%   31C    P8    N/A /  75W |     22MiB /  1999MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1073      G   /usr/lib/xorg/Xorg                 15MiB |
|    0   N/A  N/A      1953      G   /usr/bin/gnome-shell                3MiB |
+-----------------------------------------------------------------------------+
  1. Cuda sample deviceQuery :
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA GeForce GTX 1050"
  CUDA Driver Version / Runtime Version          11.4 / 11.4
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 2000 MBytes (2097086464 bytes)
  (005) Multiprocessors, (128) CUDA Cores/MP:    640 CUDA Cores
  GPU Max Clock rate:                            1468 MHz (1.47 GHz)
  Memory Clock rate:                             3504 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 1048576 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total shared memory per multiprocessor:        98304 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Managed Memory:                Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.4, CUDA Runtime Version = 11.4, NumDevs = 1
Result = PASS

  1. ffmpeg debug
ffmpeg version N-106534-g487b49d8f2 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --disable-static --enable-shared
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 25.101 / 59. 25.101
  libavformat    59. 20.101 / 59. 20.101
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 30.100 /  8. 30.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'debug'.
Reading option '-init_hw_device' ... matched as option 'init_hw_device' (initialise hardware device) with argument 'cuda'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument debug.
Applying option init_hw_device (initialise hardware device) with argument cuda.
[AVHWDeviceContext @ 0x559301bd7c40] Loaded lib: libcuda.so.1
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuInit
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDeviceGetCount
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDeviceGet
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDeviceGetAttribute
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDeviceGetName
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDeviceComputeCapability
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuCtxCreate_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuCtxSetLimit
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuCtxPushCurrent_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuCtxPopCurrent_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuCtxDestroy_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemAlloc_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemAllocPitch_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemAllocManaged
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemsetD8Async
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemFree_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpy
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyAsync
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpy2D_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpy2DAsync_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyHtoD_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyHtoDAsync_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyDtoH_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyDtoHAsync_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyDtoD_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMemcpyDtoDAsync_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGetErrorName
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGetErrorString
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuCtxGetDevice
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDevicePrimaryCtxRetain
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDevicePrimaryCtxRelease
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDevicePrimaryCtxSetFlags
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDevicePrimaryCtxGetState
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDevicePrimaryCtxReset
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuStreamCreate
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuStreamQuery
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuStreamSynchronize
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuStreamDestroy_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuStreamAddCallback
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEventCreate
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEventDestroy_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEventSynchronize
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEventQuery
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEventRecord
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuLaunchKernel
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuLinkCreate
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuLinkAddData
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuLinkComplete
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuLinkDestroy
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuModuleLoadData
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuModuleUnload
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuModuleGetFunction
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuModuleGetGlobal
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuTexObjectCreate
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuTexObjectDestroy
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGLGetDevices_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGraphicsGLRegisterImage
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGraphicsUnregisterResource
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGraphicsMapResources
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGraphicsUnmapResources
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuGraphicsSubResourceGetMappedArray
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDeviceGetUuid
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuImportExternalMemory
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDestroyExternalMemory
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuExternalMemoryGetMappedBuffer
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuExternalMemoryGetMappedMipmappedArray
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMipmappedArrayGetLevel
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuMipmappedArrayDestroy
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuImportExternalSemaphore
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuDestroyExternalSemaphore
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuSignalExternalSemaphoresAsync
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuWaitExternalSemaphoresAsync
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuArray3DCreate_v2
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuArrayDestroy
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEGLStreamProducerConnect
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEGLStreamProducerDisconnect
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEGLStreamConsumerDisconnect
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEGLStreamProducerPresentFrame
[AVHWDeviceContext @ 0x559301bd7c40] Loaded sym: cuEGLStreamProducerReturnFrame
Successfully parsed a group of options.
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

  1. ffmpeg test with hwaccel
ffmpeg version N-106534-g487b49d8f2 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --disable-static --enable-shared
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 25.101 / 59. 25.101
  libavformat    59. 20.101 / 59. 20.101
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 30.100 /  8. 30.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2015-08-07T09:13:02.000000Z
  Duration: 00:00:30.53, start: 0.000000, bitrate: 411 kb/s
  Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 480x270 [SAR 1:1 DAR 16:9], 301 kb/s, 30 fps, 30 tbr, 30 tbn (default)
    Metadata:
      creation_time   : 2015-08-07T09:13:02.000000Z
      handler_name    : L-SMASH Video Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 112 kb/s (default)
    Metadata:
      creation_time   : 2015-08-07T09:13:02.000000Z
      handler_name    : L-SMASH Audio Handler
      vendor_id       : [0][0][0][0]
File 'output.mp4' already exists. Overwrite? [y/N] Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 0x564f8638d8c0] decoder->cvdl->cuvidGetDecoderCaps(&caps) failed -> CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
[h264 @ 0x564f8638d8c0] Failed setup for format cuda: hwaccel initialisation returned error.

As you can see the ffmpeg command throws error : “CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected”

What am I doing wrong?