Jetson NX OpenCV GStreamer Issue

I am using the following environment
Device: Jetson NX
JetPack: 4.6
OpenCV: 4.4.0
GStreamer: 1.16.2
Deepstream: 6.1
CUDA: 10.2

Problem:
I am using GStreamer pipeline to connect to a rtsp camera source using OpenCV Video Capture.
Code as follows

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <chrono>
#include <sys/time.h>
#include <experimental/filesystem>

// To build the program
// g++ -ggdb detect.cc -o detect `pkg-config --cflags --libs opencv`
// Change the following placeholders
// 1. <Pawword>
// 2. <ipaddress>

typedef std::chrono::high_resolution_clock CLK;
typedef std::chrono::duration<double, std::milli> MSEC;


int main(int argc, char** argv){
  std::string url = "rtsp://<url>";
  std::string pipeline = "rtspsrc location="+url;
  pipeline += " latency=0 ! rtph265depay ! h265parse"
             " ! nvv4l2decoder "
             " ! nvvideoconvert "
             " ! video/x-raw(memory:NVMM), format=RGBA "
             " ! nvvideoconvert"
             " ! video/x-raw,format=BGRx "
             " ! videoconvert"
             " ! appsink";
  auto api = cv::CAP_GSTREAMER;
  cv::VideoCapture cap;
  bool ok = cap.open(pipeline,api);
  if (!ok){
    throw std::runtime_error("Can not open camera URL.");
  }
  if (!cap.isOpened()){
    throw std::runtime_error("Source is not open");
  }
  while (ok){
    cv::Mat frame;
    auto start = CLK::now();
    auto ok = cap.read(frame);
    auto end = CLK::now();
    if (!ok || curr_frame.empty()){
      break;
    }
    // Write to Disk
    cv::imwrite(“frame.jpg”, frame);
  }  
}

I see, a delay in reading frames from the camera. Not always but once in 30 min or 1 hour. Following are the log


2022-05-06_00-03-35.528: INFO : Frame capture stuck for 1201.898433 msecs
2022-05-06_00-26-44.488: INFO : Frame capture stuck for 1091.831474 msecs
2022-05-06_01-27-20.060: INFO : Frame capture stuck for 3238.538110 msecs
2022-05-06_02-03-42.579: INFO : Frame capture stuck for 3246.393027 msecs
2022-05-06_02-27-55.360: INFO : Frame capture stuck for 3196.403677 msecs
2022-05-06_03-28-40.676: INFO : Frame capture stuck for 4628.928977 msecs
2022-05-06_04-03-47.553: INFO : Frame capture stuck for 3251.554384 msecs
2022-05-06_04-29-14.500: INFO : Frame capture stuck for 3223.365709 msecs
2022-05-06_05-29-48.860: INFO : Frame capture stuck for 3225.596420 msecs
2022-05-06_06-03-52.534: INFO : Frame capture stuck for 3247.813399 msecs
2022-05-06_06-30-22.796: INFO : Frame capture stuck for 3237.623881 msecs
2022-05-06_07-30-57.069: INFO : Frame capture stuck for 3220.008904 msecs
2022-05-06_08-03-58.388: INFO : Frame capture stuck for 4054.999025 msecs
2022-05-06_08-31-32.286: INFO : Frame capture stuck for 4452.242579 msecs
2022-05-06_09-32-11.085: INFO : Frame capture stuck for 3234.263944 msecs
2022-05-06_10-04-06.385: INFO : Frame capture stuck for 3249.989389 msecs
2022-05-06_10-33-08.213: INFO : Frame capture stuck for 3232.426650 msecs
2022-05-06_11-33-47.325: INFO : Frame capture stuck for 3217.614389 msecs
2022-05-06_12-04-11.415: INFO : Frame capture stuck for 3212.730782 msecs
2022-05-06_12-34-40.102: INFO : Frame capture stuck for 3241.078578 msecs
2022-05-06_13-35-24.303: INFO : Frame capture stuck for 3243.878039 msecs
2022-05-06_14-04-16.439: INFO : Frame capture stuck for 3242.876017 msecs
2022-05-06_14-35-58.604: INFO : Frame capture stuck for 3214.990012 msecs
2022-05-06_15-36-42.445: INFO : Frame capture stuck for 3250.851372 msecs
2022-05-06_16-04-24.520: INFO : Frame capture stuck for 3227.267266 msecs
2022-05-06_16-37-22.803: INFO : Frame capture stuck for 3234.739380 msecs
2022-05-06_17-38-02.146: INFO : Frame capture stuck for 3232.435361 msecs
2022-05-06_18-04-32.580: INFO : Frame capture stuck for 3235.843994 msecs
2022-05-06_18-38-42.533: INFO : Frame capture stuck for 3222.578070 msecs
2022-05-06_19-39-17.620: INFO : Frame capture stuck for 3222.435453 msecs
2022-05-06_20-04-37.581: INFO : Frame capture stuck for 3235.180493 msecs
2022-05-06_20-39-52.341: INFO : Frame capture stuck for 3251.455835 msecs
2022-05-06_21-40-27.315: INFO : Frame capture stuck for 3250.736630 msecs
2022-05-06_22-04-42.625: INFO : Frame capture stuck for 3234.879663 msecs

I need some help to resolve this issue.

While this happens, the following are the system resource usage

  1. CPU usage is normal at 15 - 20 % along with other applications running
  2. RAM usage is 70 - 75% along with other application is running

Moving this topic to the Jetson Xavier NX category for visibility.

Hi,
Please apply the steps and check if there is improvement:

  1. Execute the commands to run CPU cores at maximum clock:
$ sudo nvpmodel -m 2
$ sudo jetson_clocks
  1. Set the property to nvv4l2decoder
  enable-max-performance: Set to enable max performance
                        flags: readable, writable
                        Boolean. Default: false

Our current power mode is 8 which is using the max clock. As per this documentation
https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-3261/Tegra%20Linux%20Driver%20Package%20Development%20Guide/power_management_jetson_xavier.html#wwpID0E0XO0HA

When I run the command nvpmodel -q

I see the following errors

NV Fan Mode:quiet
NV Power Mode: MODE_15W_6CORE
2
NVPM ERROR: Error opening /sys/kernel/nvpmodel_emc_cap/emc_iso_cap: 13
NVPM ERROR: failed to read PARAM EMC: ARG MAX_FREQ: PATH /sys/kernel/nvpmodel_emc_cap/emc_iso_cap
NVPM ERROR: Error opening /sys/kernel/nvpmodel_emc_cap/nafll_dla: 13
NVPM ERROR: failed to read PARAM DLA_CORE: ARG MAX_FREQ: PATH /sys/kernel/nvpmodel_emc_cap/nafll_dla
NVPM ERROR: Error opening /sys/kernel/nvpmodel_emc_cap/nafll_dla_falcon: 13
NVPM ERROR: failed to read PARAM DLA_FALCON: ARG MAX_FREQ: PATH /sys/kernel/nvpmodel_emc_cap/nafll_dla_falcon
NVPM ERROR: Error opening /sys/kernel/nvpmodel_emc_cap/nafll_pva_vps: 13
NVPM ERROR: failed to read PARAM PVA_VPS: ARG MAX_FREQ: PATH /sys/kernel/nvpmodel_emc_cap/nafll_pva_vps
NVPM ERROR: Error opening /sys/kernel/nvpmodel_emc_cap/nafll_pva_core: 13
NVPM ERROR: failed to read PARAM PVA_CORE: ARG MAX_FREQ: PATH /sys/kernel/nvpmodel_emc_cap/nafll_pva_core
NVPM ERROR: Error opening /sys/kernel/nvpmodel_emc_cap/nafll_cvnas: 13
NVPM ERROR: failed to read PARAM CVNAS: ARG MAX_FREQ: PATH /sys/kernel/nvpmodel_emc_cap/nafll_cvnas
NVPM ERROR: Error opening /sys/devices/c250000.i2c/i2c-7/7-0040/iio:device0/warn_current_limit_0: 13
NVPM ERROR: failed to read PARAM VDDIN_OC_LIMIT: ARG WARN: PATH /sys/devices/c250000.i2c/i2c-7/7-0040/iio:device0/warn_current_limit_0
NVPM ERROR: Error opening /sys/devices/c250000.i2c/i2c-7/7-0040/iio:device0/crit_current_limit_0: 13
NVPM ERROR: failed to read PARAM VDDIN_OC_LIMIT: ARG CRIT: PATH /sys/devices/c250000.i2c/i2c-7/7-0040/iio:device0/crit_current_limit_0
NVPM ERROR: Error opening /sys/bus/platform/devices/pwm-fan/fan_profile: 13
NVPM ERROR: Fan failed to set mode:quiet

Hi,
Please run the command with sudo

ok got it