{"id":15910608,"url":"https://github.com/thibaultbee/streampack","last_synced_at":"2025-04-07T12:09:56.067Z","repository":{"id":37977786,"uuid":"262623449","full_name":"ThibaultBee/StreamPack","owner":"ThibaultBee","description":"RTMP/RTMPS and SRT live streaming libraries for Android","archived":false,"fork":false,"pushed_at":"2024-04-13T07:56:28.000Z","size":4588,"stargazers_count":151,"open_issues_count":12,"forks_count":59,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-13T21:14:40.157Z","etag":null,"topics":["aac","android","av1-encoder","h264","h264-encoder","h265","hevc","hevc-encoder","live-streaming","live-streaming-videos","opus-codec","rtmp","sdk","srt","streaming","streaming-api","streaming-video","video","vp9"],"latest_commit_sha":null,"homepage":"https://thibaultbee.github.io/StreamPack/index.html","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThibaultBee.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"ThibaultBee"}},"created_at":"2020-05-09T17:30:14.000Z","updated_at":"2024-04-16T16:48:41.917Z","dependencies_parsed_at":"2023-10-13T02:47:45.161Z","dependency_job_id":"83662d45-9d7d-480a-b4fa-9b9c8434f585","html_url":"https://github.com/ThibaultBee/StreamPack","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThibaultBee%2FStreamPack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThibaultBee%2FStreamPack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThibaultBee%2FStreamPack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThibaultBee%2FStreamPack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThibaultBee","download_url":"https://codeload.github.com/ThibaultBee/StreamPack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"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":["aac","android","av1-encoder","h264","h264-encoder","h265","hevc","hevc-encoder","live-streaming","live-streaming-videos","opus-codec","rtmp","sdk","srt","streaming","streaming-api","streaming-video","video","vp9"],"created_at":"2024-10-06T15:11:04.138Z","updated_at":"2025-04-07T12:09:56.050Z","avatar_url":"https://github.com/ThibaultBee.png","language":"Kotlin","readme":"# StreamPack: RTMP and [SRT](https://github.com/Haivision/srt) live streaming SDK for Android\n\nStreamPack is a modular live streaming library for Android made for both demanding video\nbroadcasters and new video enthusiasts.\n\nIt is designed to be used in live streaming and gaming apps.\n\n## Setup\n\nGet StreamPack core latest artifacts on mavenCentral:\n\n```groovy\ndependencies {\n    implementation 'io.github.thibaultbee:streampack:2.6.1'\n    // For RTMP\n    implementation 'io.github.thibaultbee:streampack-extension-rtmp:2.6.1'\n    // For SRT\n    implementation 'io.github.thibaultbee:streampack-extension-srt:2.6.1'\n}\n```\n\nIf you use both RTMP and SRT, you might have a conflict with `libssl.so` and `libcrypto.so` because\nthey\nare both includes in native dependencies. To solve this, you can add in your `build.gradle`:\n\n```groovy\nandroid {\n    packagingOptions {\n        pickFirst '**/*.so'\n    }\n}\n```\n\n## Features\n\n* Video:\n    * Source: Cameras or Screen recorder\n    * Orientation: portrait or landscape\n    * Codec: HEVC/H.265, AVC/H.264, VP9 or AV1 (experimental,\n      see https://github.com/ThibaultBee/StreamPack/discussions/90)\n    * HDR (experimental, see https://github.com/ThibaultBee/StreamPack/discussions/91)\n    * Configurable bitrate, resolution, framerate (tested up to 60), encoder level, encoder profile\n    * Video only mode\n    * Device video capabilities\n* Audio:\n    * Codec: AAC:LC, HE, HEv2,... or Opus\n    * Configurable bitrate, sample rate, stereo/mono, data format\n    * Processing: Noise suppressor or echo cancellation\n    * Audio only mode\n    * Device audio capabilities\n* File: TS or FLV or Fragmented MP4\n    * Write to a single file or multiple chunk files\n* Streaming: RTMP/RTMPS or SRT\n    * Support for enhanced RTMP\n    * Ultra low-latency based on [SRT](https://github.com/Haivision/srt)\n    * Network adaptive bitrate mechanism for [SRT](https://github.com/Haivision/srt)\n\n## Samples\n\n### Camera and audio sample\n\nFor source code example on how to use camera and audio streamers, check\nthe [sample app directory](https://github.com/ThibaultBee/StreamPack/tree/master/demos/camera). On\nfirst launch, you will have to set RTMP url or SRT server IP in the settings menu.\n\n### Screen recorder\n\nFor source code example on how to use screen recorder streamer, check\nthe [sample screen recorder directory](https://github.com/ThibaultBee/StreamPack/tree/master/demos/screenrecorder)\n. On first launch, you will have to set RTMP url or SRT server IP in the settings menu.\n\n### Tests with a FFmpeg server\n\nFFmpeg has been used as an SRT server+demuxer+decoder for the tests.\n\n#### RTMP\n\nTells FFplay to listen on IP `0.0.0.0` and port `1935`.\n\n```\nffplay -listen 1 -i 'rtmp://0.0.0.0:1935/s/streamKey'\n```\n\nOn StreamPack sample app settings, set `Endpoint` -\u003e `Type` to `Stream to a remove RTMP device`,\nthen set the server `URL` to `rtmp://serverip:1935/s/streamKey`. At this point, StreamPack sample\napp should successfully sends audio and video frames. On FFplay side, you should be able to watch\nthis live stream.\n\n#### SRT\n\nCheck how to build FFmpeg with libsrt\nin [SRT CookBook](https://srtlab.github.io/srt-cookbook/apps/ffmpeg/). Tells FFplay to listen on\nIP `0.0.0.0` and port `9998`:\n\n```\nffplay -fflags nobuffer 'srt://0.0.0.0:9998?mode=listener'\n```\n\nOn StreamPack sample app settings, set the server `IP` to your server IP and server `Port` to `9998`\n. At this point, StreamPack sample app should successfully sends audio and video frames. On FFplay\nside, you should be able to watch this live stream.\n\n## Quick start\n\nIf you want to create a new application, you should use the\ntemplate [StreamPack boilerplate](https://github.com/ThibaultBee/StreamPack-boilerplate). In 5\nminutes, you will be able to stream live video to your server.\n\n1. Add [permissions](#permissions) to your `AndroidManifest.xml` and request them in your\n   Activity/Fragment.\n\n2. Create a `SurfaceView` to display camera preview in your layout\n\nAs a camera preview, you can use a `SurfaceView`, a `TextureView` or any\n`View` where that can provide a `Surface`.\n\nTo simplify integration, StreamPack provides an `PreviewView`.\n\n```xml\n\n\u003clayout\u003e\n    \u003cio.github.thibaultbee.streampack.views.PreviewView android:id=\"@+id/preview\"\n        android:layout_width=\"match_parent\" android:layout_height=\"match_parent\"\n        app:enableZoomOnPinch=\"true\" /\u003e\n\u003c/layout\u003e\n```\n\n`app:enableZoomOnPinch` is a boolean to enable zoom on pinch gesture.\n\n3. Instantiate the streamer (main live streaming class)\n\n```kotlin\nval streamer = CameraSrtLiveStreamer(context = requireContext())\n```\n\n4. Configure audio and video settings\n\n```kotlin\nval audioConfig = AudioConfig(\n    startBitrate = 128000,\n    sampleRate = 44100,\n    channelConfig = AudioFormat.CHANNEL_IN_STEREO\n)\n\nval videoConfig = VideoConfig(\n    startBitrate = 2000000, // 2 Mb/s\n    resolution = Size(1280, 720),\n    fps = 30\n)\n\nstreamer.configure(audioConfig, videoConfig)\n```\n\n5. Inflate the camera preview with the streamer\n\n```kotlin\n/**\n * If the preview is in a PreviewView\n */\npreview.streamer = streamer\n/**\n * If the preview is in a SurfaceView, a TextureView, or any View that can provide a Surface\n */\nstreamer.startPreview(preview)\n```\n\n6. Start the live streaming\n\n```kotlin\nstreamer.startStream(ip, port)\n```\n\n7. Stop and release the streamer\n\n```kotlin\nstreamer.stopStream()\nstreamer.disconnect()\nstreamer.stopPreview() // The StreamerSurfaceView will be automatically stop the preview\nstreamer.release()\n```\n\nFor more detailed explanation, check out\nthe [API documentation](https://thibaultbee.github.io/StreamPack).\n\n## Permissions\n\nYou need to add the following permissions in your `AndroidManifest.xml`:\n\n```xml\n\n\u003cmanifest\u003e\n    \u003c!-- Only for a live --\u003e\n    \u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n    \u003c!-- Only for a record --\u003e\n    \u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" /\u003e\n\u003c/manifest\u003e\n```\n\nFor a record, you also need to request the following dangerous\npermission: `android.permission.WRITE_EXTERNAL_STORAGE`.\n\nTo use the camera, you need to request the following permission:\n\n```xml\n\n\u003cmanifest\u003e\n    \u003cuses-permission android:name=\"android.permission.RECORD_AUDIO\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.CAMERA\" /\u003e\n\u003c/manifest\u003e\n```\n\nYour application also has to request the following dangerous\npermission: `android.permission.RECORD_AUDIO`, `android.permission.CAMERA`.\n\nFor the PlayStore, your application might declare this in its `AndroidManifest.xml`\n\n```xml\n\n\u003cmanifest\u003e\n    \u003cuses-feature android:name=\"android.hardware.camera\" android:required=\"true\" /\u003e\n    \u003cuses-feature android:name=\"android.hardware.camera.autofocus\" android:required=\"false\" /\u003e\n\u003c/manifest\u003e\n```\n\nTo use the screen recorder, you need to request the following permission:\n\n```xml\n\n\u003cmanifest\u003e\n    \u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.POST_NOTIFICATIONS\" /\u003e\n    \u003c!-- Only if you have to record audio --\u003e\n    \u003cuses-permission android:name=\"android.permission.RECORD_AUDIO\" /\u003e\n\u003c/manifest\u003e\n```\n\nYou will also have to declare the `Service`,\n\n```xml\n\n\u003capplication\u003e\n    \u003c!-- YourScreenRecorderService extends ScreenRecorderRtmpLiveService or ScreenRecorderSrtLiveService --\u003e\n    \u003cservice android:name=\".services.YourScreenRecorderService\" android:exported=\"false\"\n        android:foregroundServiceType=\"mediaProjection\" /\u003e\n\u003c/application\u003e\n```\n\n## Tips\n\n### RTMP or SRT\n\nRTMP and SRT are both live streaming protocols. SRT is a UDP-based modern protocol, it is reliable\nand ultra low latency. RTMP is a TCP-based protocol, it is also reliable but it is only low latency.\nThere are already a lot of comparison over the Internet, so here is a summary:\nSRT:\n\n- Ultra low latency (\u003c 1s)\n- HEVC support through MPEG-TS RTMP:\n- Low latency (2-3s)\n- HEVC not officially support (specification has been aban by its creator)\n\nSo, the main question is: \"which protocol to use?\"\nIt is easy: if your server has SRT support, use SRT otherwise use RTMP.\n\n### Streamers\n\nLet's start with some definitions! `Streamers` are classes that represent a live streaming pipeline:\ncapture, encode, mux and send. They comes in multiple flavours: with different audio and video\nsource, with different endpoints and functionalities... 3 types of base streamers are available:\n\n- `CameraStreamers`: for streaming from camera\n- `ScreenRecorderStreamers`: for streaming from screen\n- `AudioOnlyStreamers`: for streaming audio only\n\nYou can find specific streamers for File or for Live. Currently, there are 2 main endpoints:\n\n- `FileStreamer`: for streaming to file\n- `LiveStreamer`: for streaming to a RTMP or a SRT live streaming server\n\nFor example, you can use `AudioOnlyFlvFileStreamer` to stream from microphone only to a FLV file.\nAnother example, you can use `CameraRtmpLiveStreamer` to stream from camera to a RTMP server.\n\nIf a streamer is missing, of course, you can also create your own. You should definitely submit it\nin a [pull request](https://github.com/ThibaultBee/StreamPack/pulls).\n\n### Get device capabilities\n\nHave you ever wonder: \"What are the supported resolution of my cameras?\" or \"What is the supported\nsample rate of my audio codecs?\"? `Helpers` classes are made for this. All `Streamer` comes with a\nspecific `Helper` object (I am starting to have the feeling I repeat myself):\n\n```kotlin\nval helper = streamer.helper\n```\n\n### Get extended settings\n\nIf you are looking for more settings on streamer, like the exposure compensation of your camera, you\nmust have a look on `Settings` class. All together: \"All `Streamer` comes with a specific `Settings`\nobject\":\n\n```kotlin\nstreamer.settings\n```\n\nFor example, if you want to change the exposure compensation of your camera, on a `CameraStreamers`\nyou can do it like this:\n\n```kotlin\nstreamer.settings.camera.exposure.compensation = value\n```\n\nMoreover you can check exposure range and step with:\n\n```kotlin\nstreamer.settings.camera.exposure.availableCompensationRange\nstreamer.settings.camera.exposure.availableCompensationStep\n```\n\n### Screen recorder Service\n\nTo record the screen, you have to use one of the `ScreenRecorderStreamers` inside\nan [Android Service](https://developer.android.com/guide/components/services). To simplify this\nintegration, StreamPack provides several `ScreenRecorderService` classes. Extends one of these class\nand overrides `onNotification` to customise the notification.\n\n### Android SDK version\n\nEven if StreamPack sdk supports a `minSdkVersion` 21. I strongly recommend to set the\n`minSdkVersion` of your application to a higher version (the highest is the best!) for higher\nperformance.\n\n## Licence\n\n    Copyright 2021 Thibault B.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":["https://github.com/sponsors/ThibaultBee"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthibaultbee%2Fstreampack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthibaultbee%2Fstreampack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthibaultbee%2Fstreampack/lists"}