I have received a RGB888 picture from udp, and I want to scale it by hardware not the CPU. But I don’t know how to do it. Because I don’t know push the memory to the gst pipe. I’m using python and opencv.
Hi,
Hardware converter does not support RGB888. You would need to use software converter to convert to RGBA or BGRx like this sample:
Displaying to the screen with OpenCV and GStreamer - #9 by DaneLLL
Hello! @DaneLLL
import cv2
# print(cv2.getBuildInformation())
path = "rtspsrc location=\"rtsp://192.168.19.100:554/h264/ch35/main/av_stream\" ! rtph265depay ! h265parse ! omxh265dec ! nvvidconv ! video/x-raw, format=(string)BGRx! videoconvert ! video/x-raw,format=BGR ! appsink"
cap = cv2.VideoCapture(path, cv2.CAP_GSTREAMER)
gst_out = "appsrc ! videoconvert ! video/x-raw,format=(string)BGRx ! nvvidconv ! video/x-raw,width=3840,height=2160,format=(string)BGRx ! nvdrmvideosink conn_id=0 plane_id=0 set_mode=0"
writer = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(25), (int(3840), int(2160)))
while cap.isOpened():
success,frame = cap.read()
if not success:
print("error")
break
writer.write(frame)
cv2.waitKey(1)
I find that 1080 is ok. The src is 1080. I want to scale it to 4k and display. There is no error tips. What’s wrong with the command line?
The command is work well like this.
gst-launch-1.0 rtspsrc location=“rtsp://192.168.19.100:554/h264/ch35/main/av_stream” ! rtph265depay ! h265parse ! omxh265dec ! nvvidconv ! “video/x-raw,width=3840,height=2160, format=(string)BGRx” ! nvdrmvideosink conn_id=0 plane_id=0 set_mode=0
Hi,
Please try this:
gst_out = "appsrc ! videoconvert ! video/x-raw,width=1920,height=1080,format=(string)BGRx ! nvvidconv ! video/x-raw,width=3840,height=2160,format=(string)BGRx ! nvdrmvideosink conn_id=0 plane_id=0 set_mode=0"
And probably need to set resolution of source in cv2.VideoWriter():
writer = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(25), (int(1920), int(1080)))
gst_out = "appsrc ! videoconvert ! video/x-raw,width=1920,height=1080,format=(string)BGRx ! nvvidconv ! video/x-raw,width=3840,height=2160,format=(string)BGRx ! nvdrmvideosink conn_id=0 plane_id=0 set_mode=0"
writer = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(25), (int(1920), int(1080)))
Can not display. error is
(python3:25574): GStreamer-CRITICAL **: 12:55:27.988: gst_caps_is_empty: assertion ‘GST_IS_CAPS (caps)’ failed
(python3:25574): GStreamer-CRITICAL **: 12:55:27.989: gst_caps_truncate: assertion ‘GST_IS_CAPS (caps)’ failed
(python3:25574): GStreamer-CRITICAL **: 12:55:27.989: gst_caps_fixate: assertion ‘GST_IS_CAPS (caps)’ failed
(python3:25574): GStreamer-CRITICAL **: 12:55:27.989: gst_caps_get_structure: assertion ‘GST_IS_CAPS (caps)’ failed
(python3:25574): GStreamer-CRITICAL **: 12:55:27.989: gst_structure_get_string: assertion ‘structure != NULL’ failed
(python3:25574): GStreamer-CRITICAL **: 12:55:27.989: gst_mini_object_unref: assertion ‘mini_object != NULL’ failed
gst_out = "appsrc ! videoconvert ! video/x-raw,width=1920,height=1080,format=(string)BGRx ! nvvidconv ! video/x-raw,width=3840,height=2160,format=(string)BGRx ! nvdrmvideosink conn_id=0 plane_id=0 set_mode=0"
writer = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(25), (int(3840), int(2160)))
Can not display. error is
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module appsrc0 reported: Internal data stream error.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1663) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1663) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1663) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
Hi,
We try to save to a video file and it works. Please try:
import sys
import cv2
def read_cam():
cap = cv2.VideoCapture("filesrc location=/opt/nvidia/deepstream/deepstream-6.0/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink ")
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print('Src opened, %dx%d @ %d fps' % (w, h, fps))
gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,width=1920,height=1080,format=BGRx ! nvvidconv ! video/x-raw(memory:NVMM),width=3840,height=2160 ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=test.mkv "
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(fps), (int(w), int(h)))
if not out.isOpened():
print("Failed to open output")
exit()
if cap.isOpened():
while True:
ret_val, img = cap.read();
if not ret_val:
break;
out.write(img);
cv2.waitKey(1)
else:
print("pipeline open failed")
print("successfully exit")
cap.release()
out.release()
if __name__ == '__main__':
read_cam()
We never try nvdrmvideosink in cv2.VideoWriter(). If you have tried it and it works for 1080p but fails in 4K, probably the TV does not support 4K resolution. Or the TV is not set to 4K mode.
gst-launch-1.0 rtspsrc location=“rtsp://192.168.19.100:554/h264/ch35/main/av_stream” ! rtph265depay ! h265parse ! omxh265dec ! nvvidconv ! “video/x-raw,width=3840,height=2160, format=(string)BGRx” ! nvdrmvideosink conn_id=0 plane_id=0 set_mode=0
This command works well
It is just a test.
I just want to use nvconvert in python.
Can you show me how to do it.
Similarly, image[384021603] scale to out[9605403]
Hi,
You can use nvvidconv plugin like this:
gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,width=1920,height=1080,format=BGRx ! nvvidconv ! video/x-raw(memory:NVMM),width=3840,height=2160 ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=test.mkv "
The video file will be in 4K resolution.
I see all the sample is filesink at last. If I want to save it in a python array out[1000].
How can I let the data write to the array?
Thanks!
Hi,
This may not be supported in OpenCV. It has its own function for scaling the image. May not be able to switch to use hardware converter in TX2 NX. You shall have to use OpenCV functions.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.