Jetsons have HW engine NVDEC for video decoding, better keep you GPU usage for something else.
Assuming your USB/MJPG camera is video node /dev/video1
and that v4l2-ctl -d1 --list-formats-ext
reports a mode 1280x720@30 in MJPG format, you may read camera, decode and display with:
gst-launch-1.0 v4l2src device=/dev/video1 ! image/jpeg,format=MJPG,width=1280,height=720,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! autovideosink
When ok, be sure you’ve built opencv with GStreamer support and installed to your python env if using python:
import cv2
print(cv2.getBuildInformation())
If ok, you may try using an opencv VideoCapture with gstreamer backend:
# Capture BGRx frames into opencv
cap = cv2.VideoCapture("v4l2src device=/dev/video1 ! image/jpeg,format=MJPG,width=1280,height=720,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw,format=BGRx ! appsink drop=1", cv2.CAP_GSTREAMER)
# Or capture BGR frames into opencv
#cap = cv2.VideoCapture("v4l2src device=/dev/video1 ! image/jpeg,format=MJPG,width=1280,height=720,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1", cv2.CAP_GSTREAMER)
if not cap.isOpened():
print("failed to open video capture")
exit(-1)
cv2.namedWindow("mjpgCam", cv2.WINDOW_AUTOSIZE)
frames=0
while frames < 3000:
ret_val, img = cap.read();
if not ret_val:
break
frames = frames + 1
cv2.imshow('mjpgCam',img)
if cv2.waitKey(1) == ord('q'):
break
cv2.destroyAllWindows()
cap.release()
Don’t worry about the warning, a live source has no duration.