Jetson-utils VideoSource fails, but Video-Viewer works? (SOLVED)

I am attempting to run the minimal example found here example

I compiled with this cmakelist:
cmake_minimum_required(VERSION 3.1)
project(test_inference LANGUAGES CUDA CXX)

find_package(OpenCV 4.4 REQUIRED)
set(CUDADIR /usr/local/cuda-10.2/targets/aarch64-linux/include)
include_directories(${OpenCV_INCLUDE_DIRS} ${CUDADIR})

find_package(CUDA 10.2 REQUIRED)

add_executable(main test-jetson-utils-opencv.cpp)
target_link_libraries(main ${OpenCV_LIBS} ${CUDA_LIBRARIES} jetson-inference jetson-utils nvinfer nvinfer_plugin nvcaffe_parser)

The program compiles and runs. Based on the output the videooutput and videosource open and launch however the video source fails at the first frame test. Any clues on where I should look? Is it a compilation/linking difference between video-viewer and the test example?

GST_ARGUS: Running with following settings:
   Camera index = 0 
   Camera mode  = 2 
   Output Stream W = 1920 H = 1080 
   seconds to Run    = 0 
   Frame Rate = 29.999999 
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[gstreamer] gstCamera -- onPreroll
[gstreamer] gstCamera -- map buffer size was less than max size (3110400 vs 3110407)
[gstreamer] gstCamera recieve caps:  video/x-raw, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, format=(string)NV12
[gstreamer] gstCamera -- recieved first frame, codec=raw format=nv12 width=1920 height=1080 size=3110407
Error: failed to capture first video frame
[gstreamer] gstCamera -- stopping pipeline, transitioning to GST_STATE_NULL
RingBuffer -- allocated 4 buffers (3110407 bytes each, 12441628 bytes total)
[gstreamer] gstreamer changed state from READY to PAUSED ==> mysink
[gstreamer] gstreamer message async-done ==> pipeline0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> mysink
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> pipeline0
GST_ARGUS: Cleaning up

(main:29535): GStreamer-CRITICAL **: 08:49:29.755: gst_mini_object_set_qdata: assertion 'object != NULL' failed
CONSUMER: Done Success
GST_ARGUS: Done Success
[gstreamer] gstCamera -- pipeline stopped

Thanks!

Hi @spacebaseone, I think the issue might be that the program exits after the first frame fails to read, before giving the camera a chance to fully initialize:

	uchar3* image = NULL;
	if( !input->Capture(&image, 1000) )
	{
		std::cerr << "Error: failed to capture first video frame" << std::endl;
		delete output;
		delete input;
		exit(3);
	}

Note that sometimes the camera may take more than a second to read the first frame. So you might want to change that to:

if( !input->Capture(&image, 5000) )

And if that still doesn’t work, add a loop there so keeps trying to grab the first frame as opposed to exiting.

You are the man!! Thanks @dusty_nv up and running. I’m using your utils to “hopefully” improve the performance of some USB cameras that are currently being fully handled in CPU. Who wants to do that when you have fresh green GPU to use…