FFmpeg. CUDA decode. Past duration too large. Variable FPS Please see my input udp stream information: 


  ffprobe udp://IP:PORT


Input #0, mpegts, from 'udp://IP:PORT':
  Duration: N/A, start: 42243.737022, bitrate: N/A
  Program 17
  . . .
    Stream #0:0[0x781]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 24.67 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x782](Tam): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 64 kb/s
    Stream #0:2[0x783](Kan): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 64 kb/s


And run this command again:


  ffprobe udp://IP:PORT


Input #0, mpegts, from 'IP:PORT':
  Duration: N/A, start: 42589.601022, bitrate: N/A
  . . . 
  Program 17
    Stream #0:0[0x781]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 24.58 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x782](Tam): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 64 kb/s
    Stream #0:2[0x783](Kan): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 64 kb/s


Please pay attention to FPS value. In the first execution it 24.67 and in the second it 24.58

I want to transcode this stream with the following command:


  ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -deint 2 -i
  "udp://IP:PORT" -map 0:#0x0781 -map 
  0:#0x0782 -vcodec h264_nvenc -acodec libfdk_aac -f flv rtmp://IP/test/name


Please see the log:

Past duration 0.981102 too large
frame=83 fps=0.0 q=18.0 size=502kB time=00:00:04.05 bitrate=1015.4kbits/s dup=0 drop=80 speed=7.42x  
frame=96 fps=90 q=18.0 size=643kB time=00:00:04.69 bitrate=1122.1kbits/s dup=0 drop=93 speed=4.38x  
frame=111 fps=70 q=18.0 size=802kB time=00:00:05.14 bitrate=1278.1kbits/s dup=0 drop=108 speed=3.26x 
frame=121 fps=57 q=19.0 size=921kB time=00:00:05.61 bitrate=1344.7kbits/s dup=0 drop=118 speed=2.64x 
frame=137 fps=49 q=19.0 size=1096kB time=00:00:06.25 bitrate=1436.4kbits/s dup=0 drop=134 speed=2.26x


I also can add the framerate parameter "-r". As follow:


  ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -deint 2 -r 25 -i
  "udp://IP:PORT" -map 0:#0x0781 -map 
  0:#0x0782 -vcodec h264_nvenc -r 25 -acodec libfdk_aac -f flv rtmp://IP/test/name


In this case this warning is not shows. But the transcoding FFmpeg process failed after 10-15 seconds, without any errors in the log. 
Everything works fine if I do it via software decoding:


  ffmpeg -y -i
  "udp://IP:PORT" -map 0:#0x0781 -map 
  0:#0x0782 -vcodec h264_nvenc -acodec libfdk_aac -f flv rtmp://IP/test/name


Also everything works fine if I transcoding it to the local file and specify framerate:


  ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -deint 2 -r 25 -i
  "udp://IP:PORT" -map 0:#0x0781 -map 
  0:#0x0782 -vcodec h264_nvenc -r 25 -acodec libfdk_aac -f flv result.flv


This issue affects only for some input streams.
How can I transcode this UDP stream to FLV stream with CUDA decoding?
The key -drop_second_field 1 fixed this issue.  And result command looks as follow: 


  ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -deint 2 -drop_second_field 1
  -i "udp://IP:PORT"  -vcodec h264_nvenc -acodec libfdk_aac -f flv rtmp://IP/test/name



What I think about this problem: at the moment in cuda decoding we can use only 2 deinterlace variants: 


-deint 1 it's bob deinterlacing,
-deint 2 it's adaptive deinterlacing.


Both of these variants are increase bitrate, because after deinterlacing each field(half of frame) displaying as frame (framerate is doubled) Bitrate is grow and if fps is variable we got timestamps issue. And when we enable drop second field then everything looks fine with bitrate and timestamps.