Haibo Chen(陈海博) 5dc292ce64 NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333)
## Introduce

This PR adds support for viewing streams via the RTSP protocol. Note
that it only supports viewing streams, not publishing streams via RTSP.

Currently, only publishing via RTMP is supported, which is then
converted to RTSP. Further work is needed to support publishing RTC/SRT
streams and converting them to RTSP.

## Usage

Build and run SRS with RTSP support:

```
cd srs/trunk && ./configure --rtsp=on && make -j16
./objs/srs -c conf/rtsp.conf
```

Push stream via RTMP by FFmpeg:

```
ffmpeg -re -i doc/source.flv -c copy -f flv rtmp://localhost/live/livestream
```

View the stream via RTSP protocol, try UDP first, then use TCP:

```
ffplay -i rtsp://localhost:8554/live/livestream
```

Or specify the transport protocol with TCP:

```
ffplay -rtsp_transport tcp -i rtsp://localhost:8554/live/livestream
```

## Unit Test

Run utest for RTSP:

```
./configure --utest=on & make utest -j16
./objs/srs_utest
```

## Regression Test

You need to start SRS for regression testing.

```
./objs/srs -c conf/regression-test-for-clion.conf
```

Then run regression tests for RTSP.

```
cd srs/trunk/3rdparty/srs-bench
go test ./srs -mod=vendor -v -count=1 -run=TestRtmpPublish_RtspPlay
```

## Blackbox Test

For blackbox testing, SRS will be started by utest, so there is no need
to start SRS manually.

```
cd srs/trunk/3rdparty/srs-bench
go test ./blackbox -mod=vendor -v -count=1 -run=TestFast_RtmpPublish_RtspPlay_Basic
```

## UDP Transport

As UDP requires port allocation, this PR doesn't support delivering
media stream via UDP transport, so it will fail if you try to use UDP as
transport:

```
ffplay -rtsp_transport udp -i rtsp://localhost:8554/live/livestream

[rtsp @ 0x7fbc99a14880] method SETUP failed: 461 Unsupported Transport
rtsp://localhost:8554/live/livestream: Protocol not supported

[2025-07-05 21:30:52.738][WARN][14916][7d7gf623][35] RTSP: setup failed: code=2057
(RtspTransportNotSupported) : UDP transport not supported, only TCP/interleaved mode is supported
```

There are no plans to support UDP transport for RTSP. In the real world,
UDP is rarely used; the vast majority of RTSP traffic uses TCP.

## Play Before Publish

RTSP supports audio with AAC and OPUS codecs, which is significantly
different from RTMP or WebRTC.

RTSP uses commands to exchange SDP and specify the audio track to play,
unlike WHEP or HTTP-FLV, which use the query string of the URL. RTSP
depends on the player’s behavior, making it very difficult to use and
describe.

Considering the feature that allows playing the stream before publishing
it, it requires generating some default parameters in the SDP. For OPUS,
the sample rate is 48 kHz with 2 channels, while AAC is more complex,
especially regarding the sample rate, which may be 44.1 kHz, 32 kHz, or
48 kHz.

Therefore, for RTSP, we cannot support play-then-publish. Instead, there
must already be a stream when playing it, so that the audio codec is
determined.

## Opus Codec

No Opus codec support for RTSP, because for RTC2RTSP, it always converts
RTC to RTMP frames, then converts them to RTSP packets. Therefore, the
audio codec is always AAC after converting RTC to RTMP.

This means the bridge architecture needs some changes. We need a new
bridge that binds to the target protocol. For example, RTC2RTMP converts
the audio codec, but RTC2RTSP keeps the original audio codec.

Furthermore, the RTC2RTMP bridge should also support bypassing the Opus
codec if we use enhanced-RTMP, which supports the Opus audio codec. I
think it should be configurable to either transcode or bypass the audio
codec. However, this is not relevant to RTSP.

## AI Contributor

Below commits are contributed by AI:

* [AI: Remove support for media transport via
UDP.](755686229f)
* [AI: Add crutial logs for each RTSP
stage.](9c8cbe7bde)
* [AI: Support AAC doec for
RTSP.](7d7cc12bae)
* [AI: Add option --rtsp for
RTSP.](f67414d9ee)
* [AI: Extract SrsRtpVideoBuilder for RTC and
RTSP.](562e76b904)

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-07-11 08:18:40 -04:00
2025-07-10 08:00:26 -04:00
2023-01-30 14:20:37 +08:00

SRS(Simple Realtime Server)

SRS/7.0 (Kai) is a simple, high-efficiency, and real-time video server, supporting RTMP/WebRTC/HLS/HTTP-FLV/SRT/MPEG-DASH/GB28181, Linux/Windows/macOS, X86_64/ARMv7/AARCH64/M1/RISCV/LOONGARCH/MIPS, and essential features.

SRS Overview

Note: For more details on the single-node architecture for SRS, please visit the following link.

SRS is licenced under MIT, and some third-party libraries are distributed under their licenses.

Usage

Please check the Getting Started guide in English or Chinese. We highly recommend using SRS with docker:

docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \
    -p 8000:8000/udp -p 10080:10080/udp ossrs/srs:5

Tips: If you're in China, use this image registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 for faster speed.

Open http://localhost:8080/ to verify, and then stream using the following FFmpeg command:

ffmpeg -re -i ./doc/source.flv -c copy -f flv -y rtmp://localhost/live/livestream

Alternatively, stream by OBS using the following configuration:

  • Service: Custom
  • Server: rtmp://localhost/live
  • Stream Key: livestream

Play the following streams using media players:

If you'd like to use WebRTC, convert RTMP to WebRTC, or convert WebRTC to RTMP, please check out the wiki documentation in either English or Chinese.

To learn more about RTMP, HLS, HTTP-FLV, SRT, MPEG-DASH, WebRTC protocols, clustering, HTTP API, DVR, and transcoding, please check the documents in English or Chinese.

If you want to use an IDE, VSCode is recommanded. VSCode supports macOS, Linux, and Windows platforms. The settings are ready. All you need to do is open the folder with VSCode and enjoy the efficiency brought by the IDE. See VSCode README for details.

Sponsor

Would you like additional assistance from us? By becoming a sponsor or backer of SRS, we can provide you with the support you need:

  • Backer: $5 per month, online text chat support through Discord.
  • Sponsor: $100 per month, online text chat plus online meeting support.

Please visit OpenCollective to become a backer or sponsor, and send us a direct message on Discord. We are currently providing support to the developers listed below:

At SRS, our goal is to create a free, open-source community that helps developers all over the world build high-quality streaming and RTC platforms for their businesses.

Contributing

The authors, TOC(Technical Oversight Committee), and contributors are listed here. The TOC members who made significant contributions and maintained parts of SRS are listed below:

  • Winlin: Founder of the project, focusing on ST and Issues/PR. Responsible for architecture and maintenance.
  • ZhaoWenjie: One of the earliest contributors, focusing on HDS and Windows. Has expertise in client technology.
  • ShiWei: Specializes in SRT and H.265, maintaining SRT and FLV patches for FFmpeg. An expert in codecs and FFmpeg.
  • XiaoZhihong: Concentrates on WebRTC/QUIC and SRT, with expertise in network QoS. Contributed to ARM on ST and was the original contributor for WebRTC.
  • WuPengqiang: Focused on H.265, initially contributed to the FFmpeg module in SRS for transcoding AAC with OPUS for WebRTC.
  • XiaLixin: Specializes in GB28181, with expertise in live streaming and WebRTC.
  • LiPeng: Concentrates on WebRTC and contributes to memory management and smart pointers.
  • ChenGuanghua: Focused on WebRTC/QoS and introduced the Asan toolchain to SRS.
  • ChenHaibo: Specializes in GB28181 and HTTP API, contributing to patches for FFmpeg with WHIP.
  • ZhangJunqin: Focused on H.265, Prometheus Exporter, and API module.

A huge THANK YOU goes out to:

We're really thankful to everyone in the community for helping us find bugs and improve the project. To stay in touch and keep helping our community, please check out this guide.

LICENSE

FOSSA Status

SRS is licenced under MIT, and some third-party libraries are distributed under their licenses.

Releases

Features

Please read FEATURES.

Changelog

Please read CHANGELOG.

Performance

Please read PERFORMANCE.

Architecture

Please read ARCHITECTURE.

Ports

Please read PORTS.

APIs

Please read APIS.

Mirrors

Please read MIRRORS.

Dockers

Please read DOCKERS.

Beijing, 2013.10
Winlin

Description
SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
Readme MIT 353 MiB
Languages
C++ 92.9%
JavaScript 3.2%
HTML 2%
Shell 1.4%
Go 0.3%
Other 0.1%