-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Request #258
Comments
This looks like you are using the wrong stream URL, or the video is not reaching your machine, which might be a networking issue. Try giving us more detail about your network connections, like your vehicle IP, and what is the stream endpoint configured in the vehicle. Below I wrote a quick general aid from the given information: If this script is running on the same computer as QGC, and QGC can receive the video, then you just need to use the same URL QGC uses to receive the video. If the stream is coming via UDP protocol, then the URL stream argument should be something like: Now, if it is coming from an RTSP server, then the URL should be something like: Thanks |
Sorry, you didn't wait for the image to upload, can you edit your comment with the uploaded image? |
That implies your topside computer (the one running the script) has the IP To explain it a bit, according to your configuration, the GStreamer pipeline running in the vehicle is sending UDP packets to two clients at If that sounds reasonable, then the problem might not be networking. Some ideas to try:
import cv2
print(cv2.getBuildInformation()) You should have a Video I/O:
DC1394: YES (2.2.7)
FFMPEG: YES
avcodec: YES (61.19.100)
avformat: YES (61.7.100)
avutil: YES (59.39.100)
swscale: YES (8.3.100)
avresample: NO
GStreamer: YES (1.24.10)
v4l/v4l2: YES (linux/videodev2.h) If you don't see a
RTP H264: gst-launch-1.0 -vc videotestsrc pattern=ball \
! video/x-raw,format=I420,width=320,height=240,framerate=30/1 \
! encodebin2 profile="video/x-h264" \
! rtph264pay config-interval=10 pt=96 \
! multiudpsink clients=127.0.0.1:5601 basic_receiver.py: import cv2
from urllib.parse import urlparse
print(cv2.getBuildInformation())
# Define your stream URL:
stream_url = "udp://0.0.0.0:5601"
parsed_url = urlparse(stream_url)
hostname = parsed_url.hostname
port = parsed_url.port
# Define a GStreamer pipeline to receive the video. Here, it's an RTP H264 via UDP:
receiver_pipeline = (
f"udpsrc address={hostname} port={port}"
" ! application/x-rtp,payload=96"
" ! queue ! rtph264depay ! h264parse"
" ! queue ! decodebin3 ! videoconvert ! video/x-raw,format=BGR"
" ! queue ! appsink"
)
# Open video stream telling opencv this is a gstreamer pipeline:
video = cv2.VideoCapture(receiver_pipeline, cv2.CAP_GSTREAMER)
if not video.isOpened():
print(f"Failed to open video stream with URL: {stream_url}")
exit(1)
width = video.get(cv2.CAP_PROP_FRAME_WIDTH)
height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = video.get(cv2.CAP_PROP_FPS)
print(f"Video stream successfully opened with URL: {stream_url} w/ caps: {width}x{height}@{fps}")
while True:
ret, frame = video.read()
if not ret:
print("Failed to grab frame from video stream.")
break
cv2.imshow("Video Stream", frame)
if cv2.waitKey(1) == 27: # ESC key
break
video.release()
cv2.destroyAllWindows() By running both the GStreamer command on a terminal, and the script on another terminal, you should be able to see a white ball flying on a black background on a spawned window. If this works, modify your script to use a GStreamer pipeline instead of the URL directly, just like in the Thanks |
Hi, I am using the following code:
I use it to capture video streams from QGC as input for my MIDAS video streams,But it always reports the following error:
How can I use a python script to capture the video stream from gstreamer?I would be grateful for any help I could get
The text was updated successfully, but these errors were encountered: