My device is a nvidia jetson nano. I want to use opencv and Gstreamer to push the processed frame image to a computer on the same LAN with the corresponding GPU acceleration enabled, which uses VLC to pull and display. But something went wrong. Nano address is 192.168.0.166, pull flow is normal, but another computer via VLC display screen, VLC using address is RTMP://192.168.0.166:8554. The code and error information are as follows:
import time
import cv2
# Cam properties
fps = 25
frame_width = 1920
frame_height = 1080
# Create capture
address = 'rtspsrc location=rtsp://admin:[email protected]:554/h264/ch1/main/av_stream latency=0 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw,width=1920,height=1080,format=BGRx ! videoconvert ! appsink '
cap = cv2.VideoCapture(address)
# Set camera properties
#cap.set(cv2.CAP_PROP_FRAME_WIDTH, frame_width)
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_height)
#cap.set(cv2.CAP_PROP_FPS, fps)
# Define the gstreamer sink
gst_str_rtp = "appsrc ! videoconvert ! nvvidconv ! nvv4l2h264enc tune=zerolatency bitrate=500 speed-preset=superfast ! h264parse ! flvmux ! rtmpsink location='rtmp://127.0.0.1:8554'"
# Check if cap is open
if cap.isOpened() is not True:
print ("Cannot open camera. Exiting.")
quit()
# Create videowriter as a SHM sink
out = cv2.VideoWriter(gst_str_rtp, 0, fps, (frame_width, frame_height), True)
# Loop it
while True:
# Get the frame
ret, frame = cap.read()
# Check
if ret is True:
cv2.imshow('frame1', frame)
if cv2.waitKey(1) == ord('q'):
break
# Do some processing
# Write to SHM
out.write(frame)
else:
print("Camera error.")
time.sleep(10)
cap.release()
(ocr) wzu@wzu-desktop:~/jjh/demo$ python gst_device_to_rtp.py
(python:13353): GStreamer-CRITICAL **: 20:20:24.125: gst_caps_is_empty: assertion 'GST_IS_CAPS (caps)' failed
(python:13353): GStreamer-CRITICAL **: 20:20:24.125: gst_caps_truncate: assertion 'GST_IS_CAPS (caps)' failed
(python:13353): GStreamer-CRITICAL **: 20:20:24.125: gst_caps_fixate: assertion 'GST_IS_CAPS (caps)' failed
(python:13353): GStreamer-CRITICAL **: 20:20:24.125: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed
(python:13353): GStreamer-CRITICAL **: 20:20:24.125: gst_structure_get_string: assertion 'structure != NULL' failed
(python:13353): GStreamer-CRITICAL **: 20:20:24.125: gst_mini_object_unref: assertion 'mini_object != NULL' failed
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261
Allocating new output: 2560x1440 (x 14), ThumbnailMode = 0
OPENMAX: HandleNewStreamFormat: 3605: Send OMX_EventPortSettingsChanged: nFrameWidth = 2560, nFrameHeight = 1440
[ WARN:0] global /home/wzu/jjh/opencv/opencv-4.5.4/modules/videoio/src/cap_gstreamer.cpp (1063) open OpenCV | GStreamer warning: unable to query duration of stream
[ WARN:0] global /home/wzu/jjh/opencv/opencv-4.5.4/modules/videoio/src/cap_gstreamer.cpp (1100) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
[ WARN:0] global /home/wzu/jjh/opencv/opencv-4.5.4/modules/videoio/src/cap_gstreamer.cpp (1673) open OpenCV | GStreamer warning: error opening writer pipeline: no property "tune" in element "nvv4l2h264enc0"
Is there a problem with my code or my "appsrc" configuration? Or VLC doesn't support RTMP pulling, so what about RTSP?