Encoder latency randomly spikes causing jerky video

I’m trying to capture video from a USB webcam (Elgato Cam Link) and stream it over the network via SRT. However I’m getting latency spikes every few frames, causing jerky video when panning etc.

KPI: v4l2: frameNumber= 1066 encoder= 10 ms pts= 17889384592

KPI: v4l2: frameNumber= 1067 encoder= 15 ms pts= 17906066540

KPI: v4l2: frameNumber= 1068 encoder= 20 ms pts= 17922757488

KPI: v4l2: frameNumber= 1069 encoder= 11 ms pts= 17939436748

KPI: v4l2: frameNumber= 1070 encoder= 22 ms pts= 17956121592

KPI: v4l2: frameNumber= 1071 encoder= 17 ms pts= 17972803279

KPI: v4l2: frameNumber= 1072 encoder= 11 ms pts= 17989491488

KPI: v4l2: frameNumber= 1073 encoder= 10 ms pts= 18006168696

KPI: v4l2: frameNumber= 1074 encoder= 11 ms pts= 18022860488

KPI: v4l2: frameNumber= 1075 encoder= 21 ms pts= 18039538008

KPI: v4l2: frameNumber= 1076 encoder= 16 ms pts= 18056222748

KPI: v4l2: frameNumber= 1077 encoder= 11 ms pts= 18072905905

KPI: v4l2: frameNumber= 1078 encoder= 10 ms pts= 18089588165

KPI: v4l2: frameNumber= 1079 encoder= 10 ms pts= 18106269008

KPI: v4l2: frameNumber= 1080 encoder= 20 ms pts= 18122952801

This is my pipeline:

gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw, width=1920, height=1080, format=YUY2' ! nvvidconv ! 'video/x-raw(memory:NVMM), width=1920, height=1080, format=NV12' ! nvv4l2h265enc bitrate=4000000 control-rate=1 preset-level=1 insert-sps-pps=1 MeasureEncoderLatency=1 ! 'video/x-h265, stream-format=byte-stream' ! mpegtsmux ! srtsink name=srt uri="srt://" latency=300

The same latency issue happens when outputting to a file or fakesink.

Does anyone know what the reason for this could be?

Please run Jetson Nano in max performance and check again. You can run sudo jetson_clocks and enable the property in nvv4l2h265enc:

  maxperf-enable      : Enable or Disable Max Performance mode
                        flags: readable, writable, changeable only in NULL or READY state
                        Boolean. Default: false

Hi DaneLLL, thanks… (I’m unable to access my old account for some reason) The “maxperf-enable=1” flag seems to have fixed the latency issue but I’m still getting the jerky video - guess the latency wasn’t the cause of it. I will open a new thread once I investigate further.