Skip to content

Latest commit

History

182 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SharpRTSP client and server

This is a thin wrapper around the fantastic SharpRTSP, mostly based off their sample code with some API enhancements to make it easier to use. Added support for streaming Opus, AV1 and H266.

SharpRTSPClient

Simple RTSP client that supports MJPEG, H264, H265, H266, AV1 for video and AAC, Opus, PCMU and PCMA for audio.

NuGet version

Create the RTSP client:

using(RTSPClientclient=newRTSPClient()){
...}

Subscribe events for video:

client.NewVideoStream+=(sender,e)=>{ ...}client.ReceivedVideoData+=(sender,e)=>{ ...}

The NewVideoStream callback will contain the video codec in e.StreamType as well as codec-specific info such as SPS/PPS from the SDP in e.StreamConfigurationData.

Subscribe events for audio:

client.NewAudioStream+=(sender,e)=>{ ...}client.ReceivedAudioData+=(sender,e)=>{ ...}

The NewAudioStream callback will contain the audio codec in e.StreamType as well as codec-specific info from the SDP in e.StreamConfigurationData.

For re-connection, you can optionally subscribe the Stopped event:

client.Stopped+=(sender,e)=>{client.TryReconnect();}

Connect to the RTSP stream:

client.Connect("rtsp://localhost:8554/stream1",RTPTransport.TCP);

Now you will start receiving callbacks with audio/video payload.

To disconnect the RTSP stream, call Stop or just dispose the client:

client.Stop();

SharpRTSPServer

Simple RTSP server that supports MJPEG, H264, H265, H266, AV1 for video and AAC, Opus, PCMU and PCMA for audio.

NuGet version

Create the server on port 8554:

using(varserver=newRTSPServer(8554,"admin","password")){
...}

Create tracks for the media you want to stream. For instance H264 video with AAC audio:

varh264Track=newH264Track();h264Track.SetParameterSets(sps,pps);// Sequence Parameter Set (SPS) and Picture Parameter Set (PPS) are provided by your video source as byte[] varaacTrack=newAACTrack(audioSpecificConfig,samplingRate,channelCount);// audioSpecificConfig is provided by your audio source as byte[], samplingRate and channelCount are also properties of the audio source

Create a stream source from the tracks an add it to the server:

varstreamSource=newRTSPStreamSource("stream1",h264Track,aacTrack);server.AddStreamSource(streamSource);

Multiple streams can be added, each identified by unique stream ID:

varstreamSource2=newRTSPStreamSource("stream2",h265Track,null);server.AddStreamSource(streamSource2);

Start listening for incoming requests:

server.StartListen();

To stream video, use the track instances and call FeedInRawSamples in regular intervals:

h264Track.FeedInRawSamples(rtpVideoBaseTime+videoPTS,newList<byte[]>{nal1,nal2, ...});

The same applies to audio:

aacTrack.FeedInRawSamples(rtpAudioBaseTime+audioPTS,newList<byte[]>{aacFrame});

Samples

RTSP Server App

Simple RTSP server that supports streaming video from multiple MP4 files.

RTSP Recorder App

Demonstrates how to record RTSP and save it as mp4.

FFmpeg RTSP Server

Sample RTSP server for ffmpeg RTP streams. Fully configurable in appsettings.json.

PCAPNG RTSP Server

PoC of re-playing RTSP from a Wireshark PcapNg file.

Credits

Most of the work has been done by SharpRTSP (https://github.com/ngraziano/SharpRTSP), this is just a convenience wrapper around it.

About

Simple RTSP server and client. Supports H264, H265, H266, AV1, AAC and Opus.

Topics

Resources

Stars

41 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages