use ffmpeg to probe rtsp urls instead of cv2

cv2 is faster (no subprocess launch) and will continue to be used for recording segments
This commit is contained in:
Josh Hawkins 2026-04-22 08:41:02 -05:00
parent f4ac063b37
commit aa7d861681

View File

@ -877,15 +877,23 @@ async def get_video_properties(
cap.release() cap.release()
return valid, width, height, fourcc, duration return valid, width, height, fourcc, duration
# try cv2 first is_rtsp = url.startswith("rtsp://")
has_video, width, height, fourcc, duration = probe_with_cv2(url)
# fallback to ffprobe if needed if is_rtsp:
if not has_video or (get_duration and duration < 0): # skip cv2 for RTSP: its FFmpeg backend has a hardcoded ~30s internal
# timeout that cannot be shortened per-call, and ffprobe bounded by
# -rw_timeout handles RTSP probing reliably
has_video, width, height, fourcc, duration = await probe_with_ffprobe(url) has_video, width, height, fourcc, duration = await probe_with_ffprobe(url)
else:
# try cv2 first for local files, HTTP, RTMP
has_video, width, height, fourcc, duration = probe_with_cv2(url)
# fallback to ffprobe if needed
if not has_video or (get_duration and duration < 0):
has_video, width, height, fourcc, duration = await probe_with_ffprobe(url)
# last resort for RTSP: try TCP transport, since default UDP may be blocked # last resort for RTSP: try TCP transport, since default UDP may be blocked
if (not has_video or (get_duration and duration < 0)) and url.startswith("rtsp://"): if (not has_video or (get_duration and duration < 0)) and is_rtsp:
has_video, width, height, fourcc, duration = await probe_with_ffprobe( has_video, width, height, fourcc, duration = await probe_with_ffprobe(
url, rtsp_transport="tcp" url, rtsp_transport="tcp"
) )