Skip to content

Choosing UDP or TCP for RTSP Playback

How RTSP transport selection affects latency, reliability, firewalls, and troubleshooting.

This English edition preserves the original commands, configuration fragments, and diagrams so the steps can be reproduced directly.

Reference diagram 1

Commands and configuration

# 查询该插件
gst-inspect rtspsrc
protocols           : Allowed lower transport protocols
                        flags: readable, writable
                        Flags "GstRTSPLowerTrans" Default: 0x00000007, "tcp+udp-mcast+udp"
                           (0x00000000): unknown          - GST_RTSP_LOWER_TRANS_UNKNOWN
                           (0x00000001): udp              - GST_RTSP_LOWER_TRANS_UDP
                           (0x00000002): udp-mcast        - GST_RTSP_LOWER_TRANS_UDP_MCAST
                           (0x00000004): tcp              - GST_RTSP_LOWER_TRANS_TCP
                           (0x00000010): http             - GST_RTSP_LOWER_TRANS_HTTP
                           (0x00000020): tls              - GST_RTSP_LOWER_TRANS_TLS
# 设置 UDP
g_object_set(rtspsrc, "protocols", "udp", NULL); 

# 设置 TCP
g_object_set(rtspsrc, "protocols", "tcp", NULL);
# 命令中如何去测试
# RTSP 流默认使用 UDP,若需切换到 TCP,可以设置 rtspsrc 的 protocols 参数:

gst-launch-1.0 rtspsrc location=rtsp://<your_rtsp_server>/stream protocols=tcp ! decodebin ! videoconvert ! autovideosink

gst-launch-1.0 rtspsrc location=rtsp://<your_rtsp_server>/stream protocols=udp ! decodebin ! videoconvert ! autovideosink
gst-launch-1.0 rtspsrc location=rtsp://<your_rtsp_server>/stream protocols=tcp ! decodebin ! videoconvert ! autovideosink
gst-launch-1.0 rtspsrc location=rtsp://<your_rtsp_server>/stream latency=200 ! decodebin ! videoconvert ! autovideosink

Notes

Use these examples as a starting point and adjust versions, device names, codecs, and network addresses for the target platform.