{"id":24060834,"url":"https://github.com/rjsachse/esp32-rtspserver","last_synced_at":"2025-05-12T19:23:03.586Z","repository":{"id":270928489,"uuid":"911879422","full_name":"rjsachse/ESP32-RTSPServer","owner":"rjsachse","description":"Esp32 Multiple Client RTSP Server with Video, Audio \u0026 Subtitles","archived":false,"fork":false,"pushed_at":"2025-02-14T23:18:33.000Z","size":332,"stargazers_count":18,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-15T00:24:03.462Z","etag":null,"topics":["arduino","arduino-library","audio","audio-streaming","camera","esp32","esp32-cam","esp32-s3","esp32cam","esp32s3","iot","multimedia","rtsp","rtsp-server","rtsp-stream","rtspserver","subtitles","subtitles-streamer","video","video-streaming"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rjsachse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["RjSachse"]}},"created_at":"2025-01-04T04:49:24.000Z","updated_at":"2025-02-14T23:18:18.000Z","dependencies_parsed_at":"2025-01-12T03:25:50.213Z","dependency_job_id":"41d9b23a-c610-49bf-a826-29a9244a5ab3","html_url":"https://github.com/rjsachse/ESP32-RTSPServer","commit_stats":null,"previous_names":["rjsachse/rtspserver","rjsachse/esp32-rtspserver"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjsachse%2FESP32-RTSPServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjsachse%2FESP32-RTSPServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjsachse%2FESP32-RTSPServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjsachse%2FESP32-RTSPServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjsachse","download_url":"https://codeload.github.com/rjsachse/ESP32-RTSPServer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240869094,"owners_count":19870724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-library","audio","audio-streaming","camera","esp32","esp32-cam","esp32-s3","esp32cam","esp32s3","iot","multimedia","rtsp","rtsp-server","rtsp-stream","rtspserver","subtitles","subtitles-streamer","video","video-streaming"],"created_at":"2025-01-09T07:15:09.210Z","updated_at":"2025-05-12T19:23:03.574Z","avatar_url":"https://github.com/rjsachse.png","language":"C++","funding_links":["https://github.com/sponsors/RjSachse","https://github.com/sponsors/rjsachse"],"categories":[],"sub_categories":[],"readme":"# ESP32-RTSPServer\n\n[![GitHub release](https://img.shields.io/github/release/rjsachse/ESP32-RTSPServer.svg)](https://github.com/rjsachse/ESP32-RTSPServer/releases)\n[![GitHub issues](https://img.shields.io/github/issues/rjsachse/ESP32-RTSPServer.svg)](https://github.com/rjsachse/ESP32-RTSPServer/issues)\n[![GitHub license](https://img.shields.io/github/license/rjsachse/ESP32-RTSPServer.svg)](https://github.com/rjsachse/ESP32-RTSPServer/blob/master/LICENSE)\n![GitHub Sponsor](https://img.shields.io/github/sponsors/rjsachse?label=Sponsor\u0026logo=GitHub)\n\n## Support This Project\n\nIf this library has been useful to you, please consider donating or sponsoring to support its development and maintenance. Your contributions help ensure that this project continues to improve and stay up-to-date, and also support future projects.\n\n[![](https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%23fe8e86)](https://github.com/sponsors/rjsachse)\n\nThank you for your support!\n\n## Overview\nESP32-RTSPServer Library is for the ESP32, designed to stream video, audio, and subtitles. This library allows you to easily create an RTSP server for streaming multimedia content using an ESP32. It supports various transport types and integrates with the ESP32 camera and I2S audio interfaces.\n\n## Features\n- **Authentication**: Able to set user and password for RTSP Stream\n- **Multiple Clients**: Multiple clients for multicast or for all transports with a define override\n- **Video Streaming**: Stream video from the ESP32 camera.\n- **Audio Streaming**: Stream audio using I2S.\n- **Subtitles**: Stream subtitles alongside video and audio.\n- **Transport Types**: Supports multiple transport types, including video-only, audio-only, and combined streams.\n- **Protocols**: Stream multicast, unicast UDP, TCP and HTTP Tunnel (TCP and HTTP is Slower).\n\n## Test Results with OV2460 on ESP32S3\n\n| Resolution | Frame Rate |\n|------------|------------|\n| QQVGA      | 50 Fps     |\n| QCIF       | 50 Fps     |\n| HQVGA      | 50 Fps     |\n| 240X240    | 50 Fps     |\n| QVGA       | 50 Fps     |\n| CIF        | 50 Fps     |\n| HVGA       | 50 Fps     |\n| VGA        | 25 Fps     |\n| SVGA       | 25 Fps     |\n| XGA        | 12.5 Fps   |\n| HD         | 12.5 Fps   |\n| SXGA       | 12.5 Fps   |\n| UXGA       | 5 Fps      |\n\n## Prerequisites\nThis library requires the ESP32 Arduino core by Espressif. Ensure you have at least version 3.1.1 installed.\n\n## Installation\n1. **Manual Installation**:\n   - Download the library from [GitHub](https://github.com/rjsachse/ESP32-RTSPServer).\n   - Unzip the downloaded file.\n   - Move the `ESP32-RTSPServer` folder to your Arduino libraries directory (usually `Documents/Arduino/libraries`).\n\n2. **Library Manager**:\n   - Open the Arduino IDE.\n   - Search for ESP32-RTSPServer\n   - or\n   - Go to `Sketch` -\u003e `Include Library` -\u003e `Add .ZIP Library...`.\n   - Select the downloaded `ESP32-RTSPServer.zip` file.\n\n## Usage\n### Include the Library\nBasic Setup\n```cpp\n#include \"RTSPConfig.h\" // Include a RTSPConfig.h file if want to change defined options\n#include \u003cESP32-RTSPServer.h\u003e\n\n\n// Include all other libraries and setups eg Camera, Audio\n\n// RTSPServer instance\nRTSPServer rtspServer;\n\n// Can set a username and password for RTSP authentication or leave blank for no authentication\nconst char *rtspUser = \"\";\nconst char *rtspPassword = \"\";\n\n// Task handles\nTaskHandle_t videoTaskHandle = NULL; \nTaskHandle_t audioTaskHandle = NULL; \nTaskHandle_t subtitlesTaskHandle = NULL; // Optional\n\nvoid getFrameQuality() { \n  sensor_t * s = esp_camera_sensor_get(); \n  quality = s-\u003estatus.quality; \n  Serial.printf(\"Camera Quality is: %d\\n\", quality);\n}\n\nvoid sendVideo(void* pvParameters) { \n  while (true) { \n    // Send frame via RTP\n    if(rtspServer.readyToSendFrame()) { // Must use\n      camera_fb_t* fb = esp_camera_fb_get();\n      rtspServer.sendRTSPFrame(fb-\u003ebuf, fb-\u003elen, quality, fb-\u003ewidth, fb-\u003eheight);\n      esp_camera_fb_return(fb);\n    }\n    vTaskDelay(pdMS_TO_TICKS(1)); \n  }\n}\n\nvoid sendAudio(void* pvParameters) { \n  while (true) { \n    size_t bytesRead = 0;\n    if(rtspServer.readyToSendAudio()) {\n      bytesRead = micInput();\n      if (bytesRead) rtspServer.sendRTSPAudio(sampleBuffer, bytesRead);\n      else Serial.println(\"No audio Recieved\");\n    }\n    vTaskDelay(pdMS_TO_TICKS(1)); // Delay for 1 second \n  }\n}\n\n// Optional\nvoid sendSubtitles(void* pvParameters) {\n  char data[100];\n  while (true) {\n    if(rtspServer.readyToSendAudio()) {\n      size_t len = snprintf(data, sizeof(data), \"FPS: %lu\", rtspServer.rtpFps);\n      rtspServer.sendRTSPSubtitles(data, len);\n    }\n  vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1 second has to be 1 second\n  }\n}\n\nvoid setup() {\n\n  getFrameQuality(); //Retrieve frame quality\n\n  // Create tasks for sending video, and subtitles\n  xTaskCreate(sendVideo, \"Video\", 1024 * 5, NULL, 9, \u0026videoTaskHandle);\n  xTaskCreate(sendAudio, \"Audio\", 1024 * 5, NULL, 8, \u0026audioTaskHandle);\n\n  // Optional\n  // Can use either a Task\n  xTaskCreate(sendSubtitles, \"Subtitles\", 1024 * 2, NULL, 7, \u0026subtitlesTaskHandle);\n  // Or Timer for subtitles\n  rtspServer.startSubtitlesTimer(onSubtitles); // 1-second period\n\n  rtspServer.maxRTSPClients = 5; // Set the maximum number of RTSP Multicast clients else enable OVERRIDE_RTSP_SINGLE_CLIENT_MODE to allow multiple clients for all transports eg. TCP, UDP, Multicast\n\n  rtspServer.setCredentials(rtspUser, rtspPassword); // Set RTSP authentication\n\n  // Initialize the RTSP server\n   //Example Setup usage:\n   // Option 1: Start RTSP server with default values\n   if (rtspServer.begin()) { \n   Serial.println(\"RTSP server started successfully on port 554\"); \n   } else { \n   Serial.println(\"Failed to start RTSP server\"); \n   }\n   \n   // Option 2: Set variables directly and then call begin\n   rtspServer.transport = RTSPServer::VIDEO_AUDIO_SUBTITLES; \n   rtspServer.sampleRate = 48000; \n   rtspServer.rtspPort = 8554; \n   rtspServer.rtpIp = IPAddress(239, 255, 0, 1); \n   rtspServer.rtpTTL = 64; \n   rtspServer.rtpVideoPort = 5004; \n   rtspServer.rtpAudioPort = 5006; \n   rtspServer.rtpSubtitlesPort = 5008;\n   if (rtspServer.begin()) { \n   Serial.println(\"RTSP server started successfully\"); \n   } else { \n   Serial.println(\"Failed to start RTSP server\"); \n   }\n   \n   // Option 3: Set variables in the begin call\n   if (rtspServer.begin(RTSPServer::VIDEO_AUDIO_SUBTITLES, 554, sampleRate)) { \n   Serial.println(\"RTSP server started successfully\"); \n   } else { \n   Serial.println(\"Failed to start RTSP server\"); \n   }\n}\n\nvoid loop() {\n\n}\n   \n```\n\n## VLC Settings\n\nFor detailed VLC settings, please refer to the [VLC Settings Guide](vlc.md).\n\n## Optional Defines\n\nYou can customize the behavior of the RTSPServer library by including a RTSPConfig.h in your sketch:\n\n```cpp\n// RTSPConfig.h\n#ifndef RTSP_CONFIG_H\n#define RTSP_CONFIG_H\n\n// Define ESP32_RTSP_LOGGING_ENABLED to enable logging\n//#define RTSP_LOGGING_ENABLED // save 7.7kb of flash\n\n// User defined options in sketch\n//#define OVERRIDE_RTSP_SINGLE_CLIENT_MODE // Override the default behavior of allowing only one client for unicast or TCP\n//#define RTSP_VIDEO_NONBLOCK // Enable non-blocking video streaming by creating a separate task for video streaming, preventing it from blocking the main sketch.\n\n#endif // RTSP_CONFIG_H\n```\n  - Enable logging for debugging purposes. This will save 7.7KB of flash memory if disabled.\n```cpp\n#define RTSP_LOGGING_ENABLED\n```\n  - Override the default behavior of allowing only one client for unicast or TCP.\n```cpp\n#define OVERRIDE_RTSP_SINGLE_CLIENT_MODE \n```\n  - Enable non-blocking video streaming. Creates a separate task for video streaming so it does not block the main sketch video task.\n```cpp\n#define RTSP_VIDEO_NONBLOCK\n```\n\n## API Reference\n\n### Class: RTSPServer\n\n#### Methods\n```cpp\nRTSPServer()\n```\n  - Description: Constructor for the RTSPServer class.\n\n```cpp\n~RTSPServer()\n```\n  - Description: Destructor for the RTSPServer class.\n```cpp\nbool init(TransportType transport = NONE, uint16_t rtspPort = 0, uint32_t sampleRate = 0, uint16_t port1 = 0, uint16_t port2 = 0, uint16_t port3 = 0, IPAddress rtpIp = IPAddress(), uint8_t rtpTTL = 255)\n```\n  - Description: Initializes the RTSP server with specified settings.\n  - Parameters:\n    - `transport` (TransportType): Type of transport (default is VIDEO_AND_SUBTITLES).\n    - `rtspPort` (uint16_t): Port number for the RTSP server (default is 554).\n    - `sampleRate` (uint32_t): Sample rate for audio streaming (default is 0).\n    - `port1` (uint16_t): Port number for video (default is 5430).\n    - `port2` (uint16_t): Port number for audio (default is 5432).\n    - `port3` (uint16_t): Port number for subtitles (default is 5434).\n    - `rtpIp` (IPAddress): IP address for RTP (default is 239.255.0.1).\n    - `rtpTTL` (uint8_t): TTL for RTP (default is 1).\n  - Returns: `bool` - `true` if the server initialized successfully, `false` otherwise.\n\n```cpp\nvoid deinit()\n```\n  - Description: Deinitializes the RTSP server.\n\n```cpp\nbool reinit()\n```\n  - Description: Reinitializes the RTSP server.\n  - Returns: `bool` - `true` if the server reinitialized successfully, `false` otherwise.\n\n```cpp\nvoid sendRTSPFrame(const uint8_t* data, size_t len, int quality, int width, int height)\n```\n  - Description: Sends a video frame via RTP.\n  - Parameters:\n    - `data` (const uint8_t*): Pointer to the frame data.\n    - `len` (size_t): Length of the frame data.\n    - `quality` (int): Quality of the frame.\n    - `width` (int): Width of the frame.\n    - `height` (int): Height of the frame.\n\n```cpp\nvoid sendRTSPAudio(int16_t* data, size_t len)\n```\n  - Description: Sends audio data via RTP.\n  - Parameters:\n    - `data` (int16_t*): Pointer to the audio data.\n    - `len` (size_t): Length of the audio data.\n\n```cpp\nvoid sendRTSPSubtitles(char* data, size_t len)\n```\n  - Description: Sends subtitle data via RTP.\n  - Parameters:\n    - `data` (char*): Pointer to the subtitle data.\n    - `len` (size_t): Length of the subtitle data.\n\n```cpp\nvoid startSubtitlesTimer(esp_timer_cb_t userCallback)\n```\n  - Description: Starts a timer for sending subtitles.\n  - Parameters:\n    - `userCallback` (esp_timer_cb_t): Callback function to be called by the timer.\n\n```cpp\nbool readyToSendFrame() const\n```\n  - Description: Checks if the server is ready to send a video frame.\n  - Returns: `bool` - `true` if ready, `false` otherwise.\n\n```cpp\nbool readyToSendAudio() const\n```\n  - Description: Checks if the server is ready to send audio data.\n  - Returns: `bool` - `true` if ready, `false` otherwise.\n\n```cpp\nbool readyToSendSubtitles() const\n```\n  - Description: Checks if the server is ready to send subtitle data.\n  - Returns: `bool` - `true` if ready, `false` otherwise.\n\n```cpp\nvoid setCredentials(const char* username, const char* password)\n```\n  - Description: Sets the credentials for basic authentication.\n  - Parameters:\n    - `username` (const char*): The username for authentication.\n    - `password` (const char*): The password for authentication.\n\n#### Variables\n```cpp\nuint32_t rtpFps\n```\n  - Description: Read current FPS.\n\n```cpp\nTransportType transport\n```\n  - Description: Type of transport. eg. VIDEO_ONLY\n```cpp\nuint3232 sampleRate\n```\n  - Description: Sample rate for audio streaming.\n```cpp\nint rtspPort\n```\n  - Description: Port number for the RTSP server.\n```cpp\nIPAddress rtpIp\n```\n  - Description: Multicast address.\n```cpp\nuint8_t rtpTTL\n```\n  - Description: TTL for RTP.\n```cpp\nuint16_t rtpVideoPort\n```\n  - Description: Port number for video.\n```cpp\nuint16_t rtpAudioPort\n```\n  - Description: Port number for audio.\n```cpp\nuint16_t rtpSubtitlesPort\n```\n  - Description: Port number for subtitles.\n```cpp\nuint8_t maxRTSPClients\n```\n  - Description: Maximum number of RTSP clients.\n\n## Support This Project\n\nIf this library has been useful to you, please consider donating or sponsoring to support its development and maintenance. Your contributions help ensure that this project continues to improve and stay up-to-date, and also support future projects.\n\n[![](https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%23fe8e86)](https://github.com/sponsors/rjsachse) \n\nThank you for your support!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjsachse%2Fesp32-rtspserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjsachse%2Fesp32-rtspserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjsachse%2Fesp32-rtspserver/lists"}