From 50b21d5be1c50911c153358dce1946a469daf9f3 Mon Sep 17 00:00:00 2001 From: chm10 Date: Sat, 24 Aug 2024 09:59:32 -0300 Subject: [PATCH 1/3] Add RTSP support and custom video sink option - Implement RTSP source handling in the GStreamer pipeline - Add command-line argument for specifying custom video sink - Update pipeline string generation to include RTSP source - Enhance flexibility by allowing user to choose video sink - Improve error handling for invalid network types - Refactor pipeline string generation for better readability --- basic_pipelines/detection.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/basic_pipelines/detection.py b/basic_pipelines/detection.py index 454675a..18fd99f 100644 --- a/basic_pipelines/detection.py +++ b/basic_pipelines/detection.py @@ -92,6 +92,7 @@ class GStreamerDetectionApp(GStreamerApp): def __init__(self, args, user_data): # Call the parent class constructor super().__init__(args, user_data) + self.video_sink = args.video_sink if hasattr(args, 'video_sink') else 'autovideosink' # Additional initialization code can be added here # Set Hailo parameters these parameters should be set based on the model used self.batch_size = 2 @@ -158,6 +159,16 @@ 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.video_source.startswith("rtsp://"): + source_element = ( + f"rtspsrc location={self.video_source} name=src_0 " + "protocols=tcp latency=2000 buffer-mode=auto " + "tcp-timeout=5000000 udp-buffer-size=2097152 ! " + "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! " + "rtph265depay ! h265parse ! avdec_h265 ! " + "videoconvert ! videoscale ! " + f"video/x-raw, format=RGB, width={self.network_width}, height={self.network_height} ! " + ) else: source_element = ( f"filesrc location={self.video_source} name=src_0 ! " @@ -220,6 +231,8 @@ def get_pipeline_string(self): default=None, help="Path to costume labels JSON file", ) + parser.add_argument('--video-sink', default='autovideosink', + help='GStreamer video sink to use (e.g., autovideosink, ximagesink, fakesink)') args = parser.parse_args() app = GStreamerDetectionApp(args, user_data) app.run() From f5ced655496af48ba9ab8c348537d6f814f00208 Mon Sep 17 00:00:00 2001 From: chm10 Date: Tue, 17 Sep 2024 02:01:32 -0300 Subject: [PATCH 2/3] feat: Implement auto-plugging for video decoding using decodebin (#40) Update the GStreamer pipeline to use decodebin for RTSP video sources Remove hardcoded H.265 video decoding elements Automatically select the appropriate decoder based on the incoming video stream's codec Ensure compatibility with various video codecs without explicit specification Maintain existing functionality for other video sources (RPI, USB, file) --- basic_pipelines/detection.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/basic_pipelines/detection.py b/basic_pipelines/detection.py index 08c047f..cd62dc2 100644 --- a/basic_pipelines/detection.py +++ b/basic_pipelines/detection.py @@ -157,14 +157,12 @@ def get_pipeline_string(self): ) elif self.video_source.startswith("rtsp://"): source_element = ( - f"rtspsrc location={self.video_source} name=src_0 " - "protocols=tcp latency=2000 buffer-mode=auto " - "tcp-timeout=5000000 udp-buffer-size=2097152 ! " - "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! " - "rtph265depay ! h265parse ! avdec_h265 ! " + f"rtspsrc location={self.video_source} name=src_0 ! " + "application/x-rtp,media=video ! " + "decodebin ! " "videoconvert ! videoscale ! " - f"video/x-raw, format=RGB, width={self.network_width}, height={self.network_height} ! " - ) + f"video/x-raw, format={self.network_format}, width={self.network_width}, height={self.network_height} ! " + ) else: source_element = ( f"filesrc location=\"{self.video_source}\" name=src_0 ! " From 3b771c079872a650c7b9571eb6d13100ac4ed23a Mon Sep 17 00:00:00 2001 From: chm10 Date: Tue, 17 Sep 2024 02:05:12 -0300 Subject: [PATCH 3/3] Include decodebin for RTSP for instance_segnentation and pose_estimation (#40) --- basic_pipelines/instance_segmentation.py | 8 ++++++++ basic_pipelines/pose_estimation.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/basic_pipelines/instance_segmentation.py b/basic_pipelines/instance_segmentation.py index 789bdd6..88dc17c 100644 --- a/basic_pipelines/instance_segmentation.py +++ b/basic_pipelines/instance_segmentation.py @@ -121,6 +121,14 @@ 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.video_source.startswith("rtsp://"): + source_element = ( + f"rtspsrc location={self.video_source} name=src_0 ! " + "application/x-rtp,media=video ! " + "decodebin ! " + "videoconvert ! videoscale ! " + f"video/x-raw, format={self.network_format}, width={self.network_width}, height={self.network_height} ! " + ) else: source_element = f"filesrc location=\"{self.video_source}\" name=src_0 ! " source_element += QUEUE("queue_dec264") diff --git a/basic_pipelines/pose_estimation.py b/basic_pipelines/pose_estimation.py index 0ea065e..37fb638 100644 --- a/basic_pipelines/pose_estimation.py +++ b/basic_pipelines/pose_estimation.py @@ -150,6 +150,14 @@ 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.video_source.startswith("rtsp://"): + source_element = ( + f"rtspsrc location={self.video_source} name=src_0 ! " + "application/x-rtp,media=video ! " + "decodebin ! " + "videoconvert ! videoscale ! " + f"video/x-raw, format={self.network_format}, width={self.network_width}, height={self.network_height} ! " + ) else: source_element = f"filesrc location=\"{self.video_source}\" name=src_0 ! " source_element += QUEUE("queue_dec264")