Skip to content
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

Support for video H.264 streams from RTSP URLs #46

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions basic_pipelines/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def __init__(self, args, user_data):
self.create_pipeline()

def get_pipeline_string(self):
print("wank")
if self.source_type == "rpi":
source_element = (
"libcamerasrc name=src_0 ! "
Expand All @@ -154,6 +155,15 @@ def get_pipeline_string(self):
f"v4l2src device={self.video_source} name=src_0 ! "
"video/x-raw, width=640, height=480, framerate=30/1 ! "
)
elif self.source_type == "rtsp":
source_element = (
f"rtspsrc location=\"{self.video_source}\" name=src_0 latency=300 ! "
+ QUEUE("queue_dec264")
+ "rtph264depay ! h264parse ! avdec_h264 max-threads=2 ! "
"video/x-raw,format=I420 ! "
)
#"queue name=queue_dec264 max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! "

else:
source_element = (
f"filesrc location=\"{self.video_source}\" name=src_0 ! "
Expand Down
6 changes: 4 additions & 2 deletions basic_pipelines/hailo_rpi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_default_parser():
parser = argparse.ArgumentParser(description="Hailo App Help")
parser.add_argument(
"--input", "-i", type=str, default="/dev/video0",
help="Input source. Can be a file, USB or RPi camera (CSI camera module). \
help="Input source. Can be a file, USB, RPi camera (CSI camera module), or RTSP/H264 URL. \
For RPi camera use '-i rpi' (Still in Beta). \
Defaults to /dev/video0"
)
Expand All @@ -97,12 +97,14 @@ def QUEUE(name, max_size_buffers=3, max_size_bytes=0, max_size_time=0, leaky='no

def get_source_type(input_source):
# This function will return the source type based on the input source
# return values can be "file", "mipi" or "usb"
# return values can be "file", "rpi", "usb", or "rtsp"
if input_source.startswith("/dev/video"):
return 'usb'
else:
if input_source.startswith("rpi"):
return 'rpi'
elif input_source.startswith("rtsp://"):
return 'rtsp'
else:
return 'file'

Expand Down
7 changes: 7 additions & 0 deletions basic_pipelines/instance_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def get_pipeline_string(self):
elif self.source_type == "usb":
source_element = f"v4l2src device={self.video_source} name=src_0 ! "
source_element += f"video/x-raw, width=640, height=480, framerate=30/1 ! "

elif self.source_type == "rtsp":
source_element = f"rtspsrc location=\"{self.video_source}\" name=src_0 latency=300 ! "
source_element += QUEUE("queue_dec264")
source_element += "rtph264depay ! h264parse ! avdec_h264 max-threads=2 ! "
source_element += "video/x-raw,format=I420 ! "

else:
source_element = f"filesrc location=\"{self.video_source}\" name=src_0 ! "
source_element += QUEUE("queue_dec264")
Expand Down
7 changes: 7 additions & 0 deletions basic_pipelines/pose_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ def get_pipeline_string(self):
elif self.source_type == "usb":
source_element = f"v4l2src device={self.video_source} name=src_0 ! "
source_element += f"video/x-raw, width=640, height=480, framerate=30/1 ! "

elif self.source_type == "rtsp":
source_element = f"rtspsrc location=\"{self.video_source}\" name=src_0 latency=300 ! "
source_element += QUEUE("queue_dec264")
source_element += "rtph264depay ! h264parse ! avdec_h264 max-threads=2 ! "
source_element += "video/x-raw,format=I420 ! "

else:
source_element = f"filesrc location=\"{self.video_source}\" name=src_0 ! "
source_element += QUEUE("queue_dec264")
Expand Down