user14107: Please see my input udp stream information: 

ffprobe udp://IP:PORT

Input #0, mpegts, from 'udp://IP:PORT':
  Duration: N/A, start: 29796.225911, bitrate: N/A
  Program 16
    Stream #0:3[0x641]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:5[0x642](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 39
    Stream #0:7[0xf3d]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:8[0xf3e](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 11
    Stream #0:2[0x13ed]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:6[0x13ee](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 3
    Stream #0:9[0x10ce]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:4[0x10cf](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 96 kb/s
  Program 1
    Stream #0:0[0x1006]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x1007](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 256 kb/s

I want to decode the video stream (Stream #0:0[0x1006]) with Program id 1  And doing it with the following command: 

ffmpeg -analyzeduration 2G -probesize 11M -y -hwaccel cuvid -c:v
  h264_cuvid -i udp://IP:PORT -map
  0:#0x1006 -f rawvideo cuda_decoded.yuv

Please see the log:
[mpegts @ 0x2351d60] decoding for stream 0 failed
Input #0, mpegts, from 'udp://IP:PORT':
  Duration: N/A, start: 30271.455156, bitrate: N/A
  Program 16
    Stream #0:5[0x641]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:6[0x642](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 39
    Stream #0:2[0xf3d]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:4[0xf3e](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 11
    Stream #0:3[0x13ed]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:8[0x13ee](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 3
    Stream #0:7[0x10ce]: Video: h264 ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 26.17 fps, 2.08 tbr, 90k tbn, 50 tbc
    Stream #0:9[0x10cf](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 96 kb/s
  Program 1
    Stream #0:0[0x1006]: Video: h264 ([2][0][0][0] / 0x0002), yuvj420p(pc, progressive), 16x32, 2.08 fps, 2.08 tbr, 90k tbn, 2514.04 tbc
    Stream #0:1[0x1007](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 256 kb/s
[h264_cuvid @ 0x240ca20] ctx->cvdl->cuvidCreateDecoder(&cudec, &cuinfo) failed -> CUDA_ERROR_INVALID_VALUE: invalid argument
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> rawvideo (native))
Error while opening decoder for input stream #0:0 : Generic error in an external library

Also I can decode it without any problems with the next command:

ffmpeg -analyzeduration 2G -probesize 11M -y -i udp://IP:PORT -map
  0:#0x1006 -f rawvideo -pix_fmt yuv420p software_decoded.yuv

This issue affects only for some input streams. 
Have you any ideas why this issue occurs and any recommendations how to fix it?

user27265: It's a bug in ffmpeg. When you explicitly specify a type of the HW acceleration (i.e. cuvid), ffmpeg assigns 0 to CUVIDDECODECREATEINFO::ulNumDecodeSurfaces and to CUVIDDECODECREATEINFO::ulNumOutputSurfaces. Consequently, a call to cuvidCreateDecoder fails, since NVDEC doesn't have surfaces to output decoded pictures.

user1871: Stream 0 is Stream #0:0[0x1006]: Video: mpeg2video for which you need -c:v mpeg2_cuvid

14107: <p>Please see my input udp stream information: <br></p>

<blockquote>
  <p>ffprobe udp://IP:PORT</p>
</blockquote>

<pre><code>Input #0, mpegts, from 'udp://IP:PORT':
  Duration: N/A, start: 29796.225911, bitrate: N/A
  Program 16
    Stream #0:3[0x641]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:5[0x642](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 39
    Stream #0:7[0xf3d]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:8[0xf3e](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 11
    Stream #0:2[0x13ed]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:6[0x13ee](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 3
    Stream #0:9[0x10ce]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:4[0x10cf](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 96 kb/s
  Program 1
    Stream #0:0[0x1006]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x1007](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 256 kb/s
</code></pre>

<p>I want to decode the video stream (Stream #0:0[0x1006]) with Program id 1 <br> And doing it with the following command: <br></p>

<blockquote>
  <p>ffmpeg -analyzeduration 2G -probesize 11M -y -hwaccel cuvid -c:v
  h264_cuvid -i udp://IP:PORT -map
  0:#0x1006 -f rawvideo cuda_decoded.yuv</p>
</blockquote>

<p>Please see the log:</p>

<pre><code>[mpegts @ 0x2351d60] decoding for stream 0 failed
Input #0, mpegts, from 'udp://IP:PORT':
  Duration: N/A, start: 30271.455156, bitrate: N/A
  Program 16
    Stream #0:5[0x641]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:6[0x642](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 39
    Stream #0:2[0xf3d]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:4[0xf3e](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 11
    Stream #0:3[0x13ed]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:8[0x13ee](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
  Program 3
    Stream #0:7[0x10ce]: Video: h264 ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 16:15 DAR 4:3], 26.17 fps, 2.08 tbr, 90k tbn, 50 tbc
    Stream #0:9[0x10cf](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 96 kb/s
  Program 1
    Stream #0:0[0x1006]: Video: h264 ([2][0][0][0] / 0x0002), yuvj420p(pc, progressive), 16x32, 2.08 fps, 2.08 tbr, 90k tbn, 2514.04 tbc
    Stream #0:1[0x1007](eng): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 256 kb/s
[h264_cuvid @ 0x240ca20] ctx-&gt;cvdl-&gt;cuvidCreateDecoder(&amp;cudec, &amp;cuinfo) failed -&gt; CUDA_ERROR_INVALID_VALUE: invalid argument
Stream mapping:
  Stream #0:0 -&gt; #0:0 (h264 (h264_cuvid) -&gt; rawvideo (native))
Error while opening decoder for input stream #0:0 : Generic error in an external library
</code></pre>

<p>Also I can decode it without any problems with the next command:</p>

<blockquote>
  <p>ffmpeg -analyzeduration 2G -probesize 11M -y -i udp://IP:PORT -map
  0:#0x1006 -f rawvideo -pix_fmt yuv420p software_decoded.yuv</p>
</blockquote>

<p><strong>This issue affects only for some input streams.</strong> </p>

<p>Have you any ideas why this issue occurs and any recommendations how to fix it?</p>
 27265: <p>It's a bug in ffmpeg. When you explicitly specify a type of the HW acceleration (i.e. cuvid), ffmpeg assigns 0 to <code>CUVIDDECODECREATEINFO::ulNumDecodeSurfaces</code> and to <code>CUVIDDECODECREATEINFO::ulNumOutputSurfaces</code>. Consequently, a call to cuvidCreateDecoder fails, since NVDEC doesn't have surfaces to output decoded pictures.</p>
 1871: <p>Stream 0 is <code>Stream #0:0[0x1006]: Video: mpeg2video</code> for which you need <code>-c:v mpeg2_cuvid</code></p>
