From b608af1d51f4599db1a70b4368c63b36a2134e8d Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Tue, 11 Nov 2025 17:26:56 -0600 Subject: [PATCH] Auto detect RTSP streams when proxy profile is selected and force FFmpeg. --- apps/proxy/ts_proxy/constants.py | 1 + apps/proxy/ts_proxy/stream_manager.py | 9 +++++---- apps/proxy/ts_proxy/utils.py | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/proxy/ts_proxy/constants.py b/apps/proxy/ts_proxy/constants.py index a72cbfc5..436062ce 100644 --- a/apps/proxy/ts_proxy/constants.py +++ b/apps/proxy/ts_proxy/constants.py @@ -33,6 +33,7 @@ class EventType: # Stream types class StreamType: HLS = "hls" + RTSP = "rtsp" TS = "ts" UNKNOWN = "unknown" diff --git a/apps/proxy/ts_proxy/stream_manager.py b/apps/proxy/ts_proxy/stream_manager.py index e80d4527..310d7c3d 100644 --- a/apps/proxy/ts_proxy/stream_manager.py +++ b/apps/proxy/ts_proxy/stream_manager.py @@ -221,10 +221,11 @@ class StreamManager: # Check stream type before connecting stream_type = detect_stream_type(self.url) - if self.transcode == False and stream_type == StreamType.HLS: - logger.info(f"Detected HLS stream: {self.url} for channel {self.channel_id}") - logger.info(f"HLS streams will be handled with FFmpeg for now - future version will support HLS natively for channel {self.channel_id}") - # Enable transcoding for HLS streams + if self.transcode == False and stream_type in (StreamType.HLS, StreamType.RTSP): + stream_type_name = "HLS" if stream_type == StreamType.HLS else "RTSP/RTP" + logger.info(f"Detected {stream_type_name} stream: {self.url} for channel {self.channel_id}") + logger.info(f"{stream_type_name} streams require FFmpeg for channel {self.channel_id}") + # Enable transcoding for HLS and RTSP/RTP streams self.transcode = True # We'll override the stream profile selection with ffmpeg in the transcoding section self.force_ffmpeg = True diff --git a/apps/proxy/ts_proxy/utils.py b/apps/proxy/ts_proxy/utils.py index b568b804..704057a3 100644 --- a/apps/proxy/ts_proxy/utils.py +++ b/apps/proxy/ts_proxy/utils.py @@ -7,19 +7,23 @@ logger = logging.getLogger("ts_proxy") def detect_stream_type(url): """ - Detect if stream URL is HLS or TS format. + Detect if stream URL is HLS, RTSP/RTP, or TS format. Args: url (str): The stream URL to analyze Returns: - str: 'hls' or 'ts' depending on detected format + str: 'hls', 'rtsp', or 'ts' depending on detected format """ if not url: return 'unknown' url_lower = url.lower() + # Check for RTSP/RTP streams first (requires FFmpeg) + if url_lower.startswith('rtsp://') or url_lower.startswith('rtp://'): + return 'rtsp' + # Look for common HLS indicators if (url_lower.endswith('.m3u8') or '.m3u8?' in url_lower or