1

I have NVIDIA Jetson Nano and FullHD Ip camera. Camera streams RTSP/h264.

I want to decode frames in python script from this camera for analizies.

So, i tried use something like that:

# import the necessary packages
from imutils.video import VideoStream
import imutils
import time
import cv2
# grab a reference to the webcam
print("[INFO] starting video stream...")
#vs = VideoStream(src=0).start()
vs = VideoStream(src="rtsp://login:[email protected]").start()
time.sleep(2.0)

# loop over frames
while True:
    # grab the next frame
    frame = vs.read()
    # resize the frame to have a maximum width of 500 pixels
    frame = imutils.resize(frame, width=500)
    # show the output frame
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break
# release the video stream and close open windows
vs.stop()
cv2.destroyAllWindows()

That's works, but in that way frame decoded on CPU. How to use GPU decoder?

1 Answer 1

1

The solution:

Use cv2.VideoCapture with GStreamer backend:

import cv2
pipeline = "rtspsrc location=\"rtsp://login:password@host:port/\" ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, format=(string)BGRx! videoconvert ! appsink"
capture = cv2.VideoCaputure(pipeline, cv2.CAP_GSTREAMER)

while capture.isOpened():
    res, frame = capture.read()
    cv2.imshow("Video", frame)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break
capture.release()
cv2.destroyAllWindows()
Sign up to request clarification or add additional context in comments.

2 Comments

when we control frame rate output of gstreamer, gradually increased memory, How to solve this problem? This problem when occurred the output rate smaller than input rate. I want to drop some frames for preventing gradually increased memory.
hi, totally offtopic, but you could use single quotes in your string to make the pipeline more readable. 'rtspsrc location="rtsp://login:password@host:port/" ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, format=(string)BGRx! videoconvert ! appsink', no need to escape the double quotes then. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.