Displaying live 4K video from USB webcam to monitor with Nano

Hello,

I have a 13MP webcam connected to the Nano with USB 3 connection and for now would just like to display the camera’s live video on a monitor. Ideally looking for 4K resolution at 30 fps. The camera is supposed to be able to do 4K at 30fps with MJPEG. The camera works with gstreamer and with cheese, but gstreamer will drop frames or have green and purple lines in the video, even with 4K at 15fps, and sometimes with 1080p at 30 fps. Cheese shows relatively clean video but is similarly at a lower framerate. Here is the gstreamer command that has been working:

gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-raw, framerate=30/1,width=3840,height=2160 ! xvimagesink

Is there a way I could use more of the CPU’s, maybe the GPU? Another way to display the video? Is it not the nano, maybe the connection instead?

All help/ideas are greatly appreciated :)

Hi,
Could you try tegra_multimedia_api sample 12_camera_v4l2_cuda? It supports MJPEG format.

It seems to work fairly well with 720p and 1080p, but with 4k it will show a frame then quit, saying this is not a JPEG.

Hi,
I can run below command with e-con See3CAM CU135:

$ ./camera_v4l2_cuda -d /dev/video0 -s 3840x2160 -f MJPEG

You may check if your source can output 4K MJPEG. Below command can show all supported formats:

$ v4l2-ctl -d /dev/video0 --list-formats-ext

I am using the e-con See3CAM_CU130 autofocus. The specs given by e-con systems says the camera can do 4k MJPEG at 30fps with a USB3 connection, which I am using. The v4l2-ctl command outputs this for MJPEG:

Index       : 1
	Type        : Video Capture
	Pixel Format: 'MJPG' (compressed)
	Name        : Motion-JPEG
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 3840x2160
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 4208x3120
			Interval: Discrete 0.050s (20.000 fps)
		Size: Discrete 4096x2160
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.008s (120.000 fps)

So it should be able to handle the 4k. This is the error I get when I run the camera_v4l2_cuda command above:

Premature end of JPEG file
Not a JPEG file: starts with 0xea 0x76

This kind of error has even occurred once with 640x480.

Hi,
1 You may configure ‘-n 30’ to dump one frame and check if it is a valid JPEG.

2 The input file size has to be complete JPEG from start of frame(0xFFD8) to end of frame(0xFFD9). We have the code to search for EOF:

// v4l2_buf.bytesused may have padding bytes for alignment
// Search for EOF to get exact size
if (eos_search_size > bytesused)
    eos_search_size = bytesused;
for (i = 0; i < eos_search_size; i++) {
    p =(uint8_t *)(ctx->g_buff[v4l2_buf.index].start + bytesused);
    if ((*(p-2) == 0xff) && (*(p-1) == 0xd9)) {
        break;
    }
    bytesused--;
}

MJPEG_EOS_SEARCH_SIZE is 4096 bytes by default. You may extend it to 8192 or 16384 and have a try.

How do I use this to check the nth frame?

Hi,
It saves one frame to file and if it’s a JPEG, you can view it through JPEG viewer.

I tried reloading everything from the Jetson SDK manager, I can now open 4k video though it is at a very low framerate. However, all the different resolutions will occasionally show green horizontal lines and slices of previous frames, the higher resolutions more often.

I don’t think the -n is saving anything, there is an Error that says

ERROR: save_frame_to_file(): (line:197) Failed to open file for frame saving

Is there any additional parameters to give -n to make it save?

Hi,
The error looks to be an permission issue and you can try to execute the command with ‘sudo’.