{"id":19233788,"url":"https://github.com/ossrs/srs-unity","last_synced_at":"2025-10-30T07:47:40.326Z","repository":{"id":65714160,"uuid":"534979772","full_name":"ossrs/srs-unity","owner":"ossrs","description":"WebRTC Samples with SRS SFU server for Unity.","archived":false,"fork":false,"pushed_at":"2023-10-10T07:49:17.000Z","size":311,"stargazers_count":78,"open_issues_count":7,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-21T04:43:28.865Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ossrs.io","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/ossrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2022-09-10T11:39:22.000Z","updated_at":"2025-03-28T08:28:18.000Z","dependencies_parsed_at":"2024-11-09T16:12:04.290Z","dependency_job_id":"dddbc433-5628-4a51-a20f-0fe66a935625","html_url":"https://github.com/ossrs/srs-unity","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ossrs/srs-unity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ossrs","download_url":"https://codeload.github.com/ossrs/srs-unity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-unity/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263300560,"owners_count":23445262,"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":[],"created_at":"2024-11-09T16:11:54.352Z","updated_at":"2025-10-30T07:47:35.295Z","avatar_url":"https://github.com/ossrs.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# srs-unity\n\n[![](https://badgen.net/discord/members/WHaPKBrRKp)](https://discord.gg/WHaPKBrRKp)\n\nVideo Streaming and WebRTC Samples for Unity.\n\nUnity supports WebRTC, see [com.unity.webrtc](https://docs.unity3d.com/Packages/com.unity.webrtc@2.4/manual/index.html) or [github](https://github.com/Unity-Technologies/com.unity.webrtc). However, the demos only work in P2P mode, not with remote SFU or SRS.\n\nTo work with SFU or WebRTC server, the best practice is to use [WHIP](https://datatracker.ietf.org/doc/draft-ietf-wish-whip/) for Unity to publish to SFU, such as SRS. Actually, you're also able to play stream by WHIP.\n\nThe most common use scenaio for publishing stream, is to covert video game as live streaming. However you can use OBS to capture the window and audio, but it enable you to capture from Unity inside, cool! It works like this:\n\n```\n(Scenario 1)\nUnity Game ---WebRTC----\u003e SRS --+-----RTMP--\u003e YouTube/FFmpeg\n                                +---WebRTC--\u003e H5/Unity\n```\n\nAnd the playing stream can be used for streaming consuming, it's a new feature enabled by Unity WebRTC. It works like this:\n\n```\n                                        (Scenario 2)\nOBS/FFmpeg ----RTMP----+--\u003e SRS --WebRTC--\u003e Unity Game\nH5/Unity -----WebRTC-----+\n```\n\nIt also allows multiple Unity Games to communicate by WebRTC. And there should be a set of new use scenarios for Unity+WebRTC+SRS, that you can finger out and please let us know\n\n## Environments\n\nWe have tested on:\n\n* Unity editor `2020.3.48f1 LTS`, other latest LTS versions should work well also.\n* WebRTC 2.4+, because CaptureStream API changed, see [#2](https://github.com/ossrs/srs-unity/issues/2) for detail.\n\nThe supported versions:\n\n| WebRTC | Supported | Note |\n|---|---|---|\n| [3.0.0-pre.6](https://github.com/Unity-Technologies/com.unity.webrtc/releases/tag/3.0.0-pre.6) | [v1.0.2](https://github.com/ossrs/srs-unity/releases/tag/v1.0.2), [v1.0.3](https://github.com/ossrs/srs-unity/releases/tag/v1.0.3) | Stable. Fix [#963](https://github.com/Unity-Technologies/com.unity.webrtc/issues/963) |\n| [3.0.0-pre.5](https://github.com/Unity-Technologies/com.unity.webrtc/releases/tag/3.0.0-pre.5) | [v1.0.1](https://github.com/ossrs/srs-unity/releases/tag/v1.0.1) | Stable |\n| [2.4.0-exp.11](https://github.com/Unity-Technologies/com.unity.webrtc/releases/tag/2.4.0-exp.11) to [3.0.0-pre.4](https://github.com/Unity-Technologies/com.unity.webrtc/releases/tag/3.0.0-pre.4) | [v1.0.1](https://github.com/ossrs/srs-unity/releases/tag/v1.0.1) | Known issue, see [#5](https://github.com/ossrs/srs-unity/issues/5) and [#882](https://github.com/Unity-Technologies/com.unity.webrtc/issues/882). |\n\nThe latest version should work well also, please file an issue if not.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n\n## Setting up project\n\nFirst, please setup you Unity Project. If you're stuck, please get help from [Discord](https://discord.gg/yZ4BnPmHAd).\n\n**Step 1:** Download and setup [Unity Hub](https://unity.com/download).\n\n1. Open `Unity Hub`.\n1. Click `Installs \u003e Install Editor`, please select one release to install.\n1. Check modules for `Unity Editor`, (Windows: make sure `Visual Studio` installed).\n\n**Step 2:** Create a Unity project.\n\n1. Open `Unity Hub`.\n1. Click `Projects \u003e New Project`.\n1. Select `3D Core` or `3D URP` template.\n1. Set the `Project Name` to `My project`.\n1. Click `Create project`, and an `Unity Editor` will be opened.\n\n**Step 3:** Install dependency package [com.unity.webrtc](https://docs.unity3d.com/Packages/com.unity.webrtc@2.4/manual/install.html).\n\n1. Click `Window \u003e Package Manager`.\n1. Click `+ \u003e Add package from git URL`.\n1. Input `com.unity.webrtc` then click `Add`.\n\n**Step 3.1** Case of Unity 2020.3 or 2021.3:\n\n1. Click `Window \u003e Package Manager`.\n1. Click `+ \u003e Advanced button` and enable `Show preview packages`\n1. Search `webrtc` and install the package.\n\n**Step 3.2** Case of Unity 2019.4:\n\n1. Click `Window \u003e Package Manager`.\n2. Click `+ \u003e Add package from git URL`.\n3. Input `com.unity.webrtc` then click `Add`.\n\n**Step 4:** Install [srs-unity](https://github.com/ossrs/srs-unity/releases) package.\n\n1. Download package [SRS.WebRTC.Samples.unitypackage](https://github.com/ossrs/srs-unity/releases/latest/download/SRS.WebRTC.Samples.unitypackage).\n1. Click `Asserts \u003e Import Package \u003e Custom Package`, select the file `SRS.WebRTC.Samples.unitypackage`, then click `Import`.\n1. From `Project` panel, open `Asserts \u003e io.ossrs \u003e Samples`, where you got all samples there.\n\n**Step 5:** Start [SRS](https://ossrs.io/lts/en-us/docs/v5/doc/getting-started) WebRTC media server:\n\n```bash\nCANDIDATE=\"192.168.1.10\"\ndocker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \\\n    --env CANDIDATE=$CANDIDATE -p 8000:8000/udp \\\n    ossrs/srs:5 ./objs/srs -c conf/docker.conf\n```\n\n\u003e Note: Make sure your SRS is `v4.0.264+` or `v5.0.62+`. Please read this [guide](https://ossrs.io/lts/en-us/docs/v5/doc/getting-started) to setup SRS.\n\n\u003e Note: Please remember to replace the `CANDIDATE` to your server IP, please read [link](https://ossrs.io/lts/en-us/docs/v5/doc/webrtc#config-candidate) for details.\n\n\u003e Note: For online service, you might need authentication and other features, please read [How to Setup a Video Streaming Service by 1-Click](https://ossrs.io/lts/en-us/blog/SRS-Cloud-Tutorial) or [How to Setup a Video Streaming Service with aaPanel](https://ossrs.io/lts/en-us/blog/BT-aaPanel) to build a service by SRS.\n\nBellow is detail guide for different use scenarios.\n\n## Usage: Publisher\n\nTo publish your WebCamera and Microphone using WebRTC. If you're stuck, please get help from [Discord](https://discord.gg/yZ4BnPmHAd).\n\nPlease follow [Setting up project](#setting-up-project), then work with `Publisher` sample.\n\n1. From `Project` panel, open `Asserts \u003e io.ossrs \u003e Samples \u003e Publisher`, then open the `Scene`.\n1. Click `Edit \u003e Play` to play Unity scene, which publish WebRTC stream to SRS.\n1. Open Main camera object in the editor and under the SRS publisher script, change the ip address and stream key to your e.g. `http://localhost:1985/rtc/v1/whip/?app=live\u0026stream=livestream`\n1. Play the WebRTC stream by [H5](http://localhost:8080/players/rtc_player.html?autostart=true).\n\n\u003e Note: Note that the `Publisher` scene require the WebCamera and Microphone permission, you can try other sample if no device.\n\nThe stream flows like this:\n\n```\nUnity ---WebRTC---\u003e SRS --WebRTC--\u003e H5/Chrome\n(WebCamera and Microphone)\n```\n\n\u003e Note: You could use other WebRTC media server and client to replace SRS and Chrome.\n\nhttps://user-images.githubusercontent.com/2777660/189331198-e045aeec-ad75-447b-8143-3b6d779e8dde.mp4\n\n\u003e Note: The latency is extremely low, which allows you to communicate with another Unity App. For example, you can use this mode to build a metting application by Unity.\n\n## Usage: Streamer\n\nTo publish your game camera and voice using WebRTC. If you're stuck, please get help from [Discord](https://discord.gg/yZ4BnPmHAd).\n\nPlease follow [Setting up project](#setting-up-project), then work with `Streamer` sample.\n\n1. From `Project` panel, open `Asserts \u003e io.ossrs \u003e Samples \u003e Streamer`, then open the `Scene`.\n1. Click `Edit \u003e Play` to play Unity scene, which publish WebRTC stream to SRS.\n1. Open Main camera object in the editor and under the SRS streamer script, change the ip address and stream key to your e.g. `http://localhost:1985/rtc/v1/whip/?app=live\u0026stream=livestream`\n1. Play the WebRTC stream by [H5](http://localhost:8080/players/rtc_player.html?autostart=true).\n\n\u003e Note: Note that the `Streamer` scene grab an extra camera in game and voice of `Main Camera`, and we add an example audio clip from [hls](https://developer.apple.com/streaming/examples/basic-stream-osx-ios4-3.html).\n\nThe stream flows like this:\n\n```\nUnity ---WebRTC---\u003e SRS --WebRTC--\u003e H5/Chrome\n(Game camera and voice)\n```\n\n\u003e Note: You could use other WebRTC media server and client to replace SRS and Chrome.\n\nhttps://user-images.githubusercontent.com/2777660/189329527-f7569003-f047-449e-8f48-ec59ddee60e4.mp4\n\n\u003e Note: A rotating cube is in the video stream, which is also the demostration of WebRTC.\n\nhttps://user-images.githubusercontent.com/2777660/189353556-047025b2-2019-4c5a-a813-7a4c888840eb.mp4\n\n\u003e Note: Please note that we also capture the audio of game, so when we mute the H5 player there is no audio.\n\n## Usage: Player\n\nTo play stream using WebRTC. If you're stuck, please get help from [Discord](https://discord.gg/yZ4BnPmHAd).\n\n\u003e Note: The stream might be published by another WebRTC client, or live stream like OBS or FFmpeg\n\nPlease follow [Setting up project](#setting-up-project), then work with `Player` sample.\n\n1. Publish the WebRTC stream by [H5](http://localhost:8080/players/rtc_publisher.html?autostart=true).\n1. From `Project` panel, open `Asserts \u003e io.ossrs \u003e Samples \u003e Player`, then open the `Scene`.\n1. Open Main camera object in the editor and under the SRS player script, change the ip address and stream key to your e.g. `http://localhost:1985/rtc/v1/whip-play/?app=live\u0026stream=livestream`\n1. Click `Edit \u003e Play` to play Unity scene, which publish WebRTC stream to SRS.\n\n\u003e Note: You're also able to publish a live stream and play it in Unity using WebRTC, see [WebRTC for Live Streaming](https://ossrs.io/lts/en-us/docs/v5/doc/getting-started#webrtc-for-live-streaming).\n\nThe stream flows like this:\n\n```\nH5/Chrome ---WebRTC---\u003e SRS --WebRTC--\u003e Unity\n```\n\n\u003e Note: You could use other WebRTC media server and client to replace SRS and Chrome.\n\nhttps://user-images.githubusercontent.com/2777660/189331098-bd7163cf-d6b9-480c-a204-ad8b721491b6.mp4\n\n\u003e Note: By converting live streaming to WebRTC, you're able to play normal stream from OBS or exists stream to Unity. For example, you can view a live sport or music by Unity.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossrs%2Fsrs-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fossrs%2Fsrs-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossrs%2Fsrs-unity/lists"}