├── .github ├── FUNDING.yml └── workflows │ └── docker-image.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── deployment-scripts ├── .gitignore ├── README.md ├── kubernetes-kustomize │ ├── deployment.yaml │ ├── ingress.yaml │ ├── kustomization.yaml │ ├── rtmp-configuration.json │ └── service.yaml ├── linode-deploy.sh ├── local-deploy.sh └── upcloud │ ├── .gitignore │ ├── requirements.txt │ └── upcloud-deploy.py └── multistreaming-server ├── Dockerfile ├── Pipfile ├── Pipfile.lock ├── index.html ├── launch-nginx-server.sh ├── nginx-conf └── nginx.conf ├── nginx-template.conf.j2 ├── rtmp-conf-generator.py ├── stunnel-conf ├── etc-default-stunnel ├── etc-stunnel-conf.d-fb.conf ├── etc-stunnel-conf.d-ig.conf └── etc-stunnel-stunnel.conf └── supervisord.conf /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [michaelkamprath] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Build the Docker image 18 | run: docker build ./multistreaming-server/ --tag multistreaming-server:$(date +%s) 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | 132 | # MacOS 133 | .DS_Store 134 | 135 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | ## [Unreleased] 5 | * Bummped various package versions. 6 | * Added python `requirements.txt` file for UpCloud deployment script. 7 | 8 | ## [0.4.2] 9 | ### Added 10 | * Support for ReStream, and by extension, platforms that ReStream supports, such as LinkedIn. 11 | 12 | ### Changed 13 | * Bumped jinja2 from 2.11.2 to 2.11.3 14 | * Updated `apk` to use the `latest-stable` rather than `edge` as `edge` appears to not be updated. 15 | * Updated `ffmpeg`, `ngtnx`, `superviserd`, and `pipenv` to their latest versions. 16 | 17 | ## [0.4.1] 18 | ### Changed 19 | * Updated `ffmpeg` to the 4.3.x version branch 20 | 21 | ### Fixed 22 | * Corrected bug that occurred when audio bit rated was configured in JSON using an integer 23 | * Corrected a bug where each transcode block pushed to all destinations 24 | 25 | ## [0.4.0] 26 | ### Added 27 | * Support for Mixcloud and DLive. 28 | * Added support for specifying transcode profiles that can be used across multiple destination configurations. 29 | * Add kubernetes manifests, fix nginx logging, streamline the dockerfile 30 | 31 | ### Changed 32 | * Refactored how processes are managed within the Docker container. Migrated to `jinja2`, use `pipfile` and `supervisord`. 33 | 34 | ### Fixed 35 | * Corrected a spelling error in the file path that the Docker image looks for the JSON configuration. 36 | * Adjusted the timing of the UpCloud deployment script to better handle timing variation in the cloud service. 37 | * Fixed a bug in the UpCloud deployment script that manifested when the configuration filepath has spaces in it. 38 | * Changed `localhost` references to `127.0.0.1` to prevent IPv6 resolution. 39 | 40 | ## [0.3.1] 41 | ### Added 42 | * Created a deployment script for running the `multistreaming-server` locally. 43 | * Created a deployment script for the [UpCloud cloud hosting service](https://upcloud.com/signup/?promo=A2CVWA). 44 | 45 | ### Changed 46 | * Improved error handling in the RTMP configuration generation script. 47 | * Improved error handling in the Lindode deploy script. 48 | 49 | ### Fixed 50 | * Correct bug in RTMP configuration generation when the audio bit rate is set. 51 | * Reinstated support for Microsoft Stream 52 | * Addressed coding style issues with the python script `rtmp-conf-generator.py` 53 | 54 | ## [0.3.0] 55 | ### Changed 56 | * **This is a major change that breaks any deployment based on prior version.** 57 | * Migrated away from using environment variables to confihure rebroadcasting destinations and instead now used a JSON file. 58 | * Cleanly enables rebroadcasting to multiple stream keys on the same platform. 59 | * Migrated 60 | 61 | ### Added 62 | * Created a deployment script for the [Linode cloud hosting service](https://www.linode.com/?r=37246e0d6a6198293308e698647804fbfe02845e). 63 | 64 | ### Fixed 65 | * Corrected how transcoding is implemented: larger buffer, better audio 66 | 67 | ## [0.2.0] 68 | ### Changed 69 | * Migrated Docker base to `jrottenberg/ffmpeg:4.2-alpine` in order to get a more robust `ffmpeg` compilation. 70 | * Migrated RTMP module to use a more recent and currently maintained branch. 71 | 72 | ### Added 73 | * Ability to transcode the stream being sent to Facebook. 74 | 75 | ## 0.1.2 76 | * First verison! 77 | 78 | 79 | [Unreleased]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.4.2...HEAD 80 | [0.4.2]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.4.1...v0.4.2 81 | [0.4.1]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.4.0...v0.4.1 82 | [0.4.0]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.3.1...v0.4.0 83 | [0.3.1]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.3.0...v0.3.1 84 | [0.3.0]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.2.0...v0.3.0 85 | [0.2.0]: https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/compare/v0.1.2...v0.2.0 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Docker Image CI](https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/actions/workflows/docker-image.yml/badge.svg)](https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/actions/workflows/docker-image.yml) 2 | 3 | # Multi-Service RTMP Broadcaster 4 | 5 | The goal of this project is to create a Docker-deployed service that will allow you to easily broadcast a live stream to multiple services (YouTube, Twitch, Facebook, etc) at the same time. This stream rebroadcaster is designed to be used by a single source / user. 6 | 7 | ## Usage 8 | The instructions here assume you are running on Linux. With some modification of the commands, you can make this Docker build work on Windows and Mac OS too. 9 | 10 | The first step is to build the docker file. After you clone this repository, `cd` into and and issue: 11 | 12 | ```sh 13 | docker build -t multistreaming-server ./multistreaming-server/ 14 | ``` 15 | 16 | Once built, start the docker image on a host that has sufficient bandwidth to handle all the rebroadcasting you will do: 17 | 18 | ```sh 19 | docker run -it -p 80:80 -p 1935:1935 \ 20 | --env MULTISTREAMING_PASSWORD=__made_up_password__ \ 21 | -v /path/to/my-rtmp-config.json:/rtmp-configuration.json \ 22 | multistreaming-server:latest 23 | ``` 24 | 25 | If this is a host than where you built the docker image, you will need to push the docker image to that host (or build it there). Alternatively, you could use the DockerHub build of this image by pulling and using the `kamprath/multistreaming-server:latest` [Docker image](https://hub.docker.com/repository/docker/kamprath/multistreaming-server). Also, if you plan on doing any transcoding when rebroadcasting a stream, you need to ensure that your docker host's CPU is sufficient for the job. It is recommend that the host CPU has at least four cores for each distinct transcoding the multi-streaming server will do. If the host CPU is not sufficient, bit rates on the transcoded streams will suffer. 26 | 27 | Note that some environment variables should be set when running the Docker image: 28 | 29 | * `MULTISTREAMING_PASSWORD` _(REQUIRED)_ - This is a password you define and will be used by your steaming software. This is a marginally secure way to prevent other people from pushing to your stream. 30 | * `CONFIG_DISABLE_RECORD` _(OPTIONAL)_ - If this env var is set to a non-empty value, the stream recording feature will be disabled. 31 | * `CONFIG_NGINX_DEBUG` _(OPTINAL)_ - If this env var is set to a non-empty value, it will enable the nginx debug logging to stderr. This is useful for debugging. 32 | * `CONFIG_FFMPEG_LOG` _(OPTIONAL)_ - If this env var is set to a non-empty value, each ffmpeg process will start logging their output to `/tmp/ffmpeg-$APP.log` in the container. This is useful for debugging issues related to encoding. 33 | * `CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE` _(OPTIONAL)_ - This env var must be a numerical value, it will be used as the global default for `-max_muxing_queue_size` argument for the ffmpeg processes. You may need to set this to a higher value (i.e: `4096`) if you run in to this [bug.](https://trac.ffmpeg.org/ticket/6375) 34 | 35 | You must also create and JSON file with the RTMP rebroadcasting configuration you desire. This file should get mapped from your local file system to the `/rtmp-configuration.json` file path within the Docker container. The JSON file has the following elements: 36 | 37 | * `endpoint`- This is the name of the RTMP ingest endpoint that the source stream will be pushed to. Defaults to `live` if not specified. 38 | * `transcodeProfiles` - This is a JSON object with keys indicating a unique identifier for a transcode profile, and the values specifying the supported transcode options. 39 | * `pixels` - The pixel dimension that the stream should be transcoded to. Formatted like "1920x1080". If not specified, defaults to "1280x720". 40 | * `videoBitRate` - The video bit rate that should be used when sending the stream to this destination. Should be a number followed by "k" or "m" for kilo- and mega- bits-per-second. If not specified defaults to "4500k". 41 | * `videoKeyFrameSecs` - The number of seconds between key frames in the transcoded stream. If not specified, defaults to 2. 42 | * `videoFrameRate` - The frames per second which the video stream will be re-encoded with, defaults to "30". 43 | * `audioBitRate` - The bit rate that should be used for the transcoded audio signal. Should be a number followed by "k" or "m" for kilo- and mega- bits-per-second. If not specified, defaults to "160k". If neither `audioBitRate` or `audioSampleRate` are specified, then the audio signal is simply copied from source with no alteration. 44 | * `audioSampleRate` - The sampling rate to be used for the transcoded audio signal. Should be an integer indicating the sampling Hertz. If not specified, defaults to `48000`. If neither `audioBitRate` or `audioSampleRate` are specified, then the audio signal is simply copied from source with no alteration. 45 | * `maxMuxingQueueSize` - Individual override for the `CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE` env var. See the env var section for the usage. 46 | * `rebroadcastList`- _Required_ Contains a list of JSON objects that each configure a distinct RTMP destination that the stream pushed to the ingest endpoint will be rebroadcasted to. At least one destination should be configured. There is no specific limit on the number of destinations except for the hardware limitations of your host. Each destination is configured with the following JSON elements: 47 | * `name` - _Required_ A distinct label for this destination. Can be any alphanumeric string with no white space. Must be distinct from all the other destination names in this list. 48 | * `platform` - _Required_ The platform that this specific rebroadcast stream should be pushed to. The default RTMP destinations will be used for each platform. Supported platforms values are: `youtube`, `facebook`, `twitch`, `instagram`, `periscope`, `microsoft-stream`, `mixcloud`, `dlive` and `custom`. Note that specifying `microsoft-stream` or `custom` will cause the `streamKey` element to be ignored if present and instead use the `fullRTMPURL` 49 | * `regionCode` - If `periscope` is specified as the platform for this destination, this is the two letter region code that is part of the Periscope server URL. If undefined, it will default to `ca` (the "US West" region) 50 | * `streamKey` - This is the stream key that identifies the unique stream on the specified platform. This value is provided by the platform. This element must be provided for all `platform` types except for `custom` and `microsoft-stream`. 51 | * `fullRTMPURL` - If `custom` or `microsoft-stream` is specified in the `platform`, the URL specified in this element is used for the forming destination URL. This should include the `rtmp://` prefix. For the `microsoft-stream` platform, this is the full URL provided in their stream set up. This element is ignored for all other platform types. 52 | * `transcode` - If present, the stream will be transcoded before rebroadcasting it to this list item's destination. Note that when using this transcoding, the stream will be trancoded to 30 FPS and CBR bit rate. The value is a JSON object with the support for same optoins as an entry in `transcodeProfiles`. Prefer to use `transcodeProfile` key if you have multiple outputs using the same encoding configuration. 53 | * `transcodeProfile` - If present, this stream will use the transcode settings provided by the `transcodeProfile` referenced by the string identifier set here. If multiple streams refer to the same `transcodeProfile`, the transcoding will only be done once. This option is mutually exclusive with the `transcode` key. 54 | 55 | 56 | Here is an example of the JSON configuration file: 57 | ```json 58 | { 59 | "endpoint": "live", 60 | "transcodeProfiles": { 61 | "720_60fps": { 62 | "pixels": "1280x720", 63 | "videoBitRate": "4500k", 64 | "videoFrameRate": 60 65 | } 66 | }, 67 | "rebroadcastList": [ 68 | { 69 | "name": "linkedin-via-restream", 70 | "platform": "restream", 71 | "streamKey": "whatever", 72 | "transcode": { 73 | "pixels": "1920x1080", 74 | "videoBitRate": "3500k", 75 | "videoKeyFrameSecs": 2, 76 | "audioBitRate": "160k", 77 | "audioSampleRate": 44100 78 | } 79 | }, 80 | { 81 | "name": "youtube", 82 | "platform": "youtube", 83 | "streamKey": "abc123" 84 | }, 85 | { 86 | "name": "facebook-1", 87 | "platform": "facebook", 88 | "streamKey": "def456", 89 | "transcodeProfile": "720_60fps" 90 | }, 91 | { 92 | "name": "facebook-2", 93 | "platform": "facebook", 94 | "streamKey": "ghi789", 95 | "transcodeProfile": "720_60fps" 96 | }, 97 | { 98 | "name": "periscope", 99 | "platform": "periscope", 100 | "regionCode": "ca", 101 | "streamKey": "jkl012", 102 | "transcode": { 103 | "pixels": "1280x720", 104 | "videoBitRate": "3500k", 105 | "videoKeyFrameSecs": 3, 106 | "audioBitRate": "128k", 107 | "audioSampleRate": 44100 108 | } 109 | } 110 | ] 111 | } 112 | ``` 113 | Note that as long as the `name` elements are different, you can have more than one destination pushing to the same `platform`, each with different `streamKey` values. 114 | 115 | If you would like to capture a recording of the stream sent to the ingest endpoint, bind a local directory on your host to the `/var/www/html/recordings/` file path within the Docker image when launching the Docker container. You can also see statistics about the various streams this server is pushing by visiting this web page: `http://__docker_host_IP_address__/stat`. You can optionally disable recording by setting the env var `CONFIG_DISABLE_RECORD` to a non-empty value. 116 | 117 | Once the Docker image is running, set up your stream software with the following parameters: 118 | 119 | * **Server** : `rtmp://__docker_host_IP_address__/__endpoint_name__` - Replace `__docker_host_IP_address__` with the IP address of your host that is running this Docker container. Also replace `__endpoint_name__` with the value used for the `endpoint` element in your JSON configuration file. 120 | * **Stream Key** : `__made_up_stream_name__?pwd=__made_up_password__` - Here `__made_up_stream_name__` is any arbitrary stream name, and `__made_up_password__` is the same password defined for `MULTISTREAMING_PASSWORD` above. 121 | 122 | In OBS, you would set the above parameters for a "Custom..." Service in the Stream settings. 123 | 124 | The next thing to do is start your stream! 125 | 126 | ## Development 127 | 128 | In order to develop on this repository, you must have a python 3.7 environment and [`Pipenv`](https://pypi.org/project/pipenv/) installed. 129 | 130 | - Clone the repository 131 | - Navigate to the `multistreaming-server/` directory 132 | - Install dependencies and create the virtual env by running `pipenv install` 133 | - Activate the virtual env by `pipenv shell` 134 | 135 | ## Future work 136 | 137 | Goals for future improvements to this project include: 138 | 139 | * Adding more streaming services 140 | * Creating a useful status web page 141 | * Create a control panel web page where you'd set stream keys rather than through a JSON file 142 | 143 | Pull requests are welcome! 144 | 145 | ## Acknowledgements 146 | 147 | This work was heavily influenced by the following articles: 148 | 149 | * The basic concept: [https://www.scaleway.com/en/docs/setup-rtmp-streaming-server/](https://www.scaleway.com/en/docs/setup-rtmp-streaming-server/) 150 | * How to use `rtmps` with Facebook: [https://dev.to/lax/rtmps-relay-with-stunnel-12d3](https://dev.to/lax/rtmps-relay-with-stunnel-12d3) 151 | -------------------------------------------------------------------------------- /deployment-scripts/.gitignore: -------------------------------------------------------------------------------- 1 | # ignore python environments set up for development 2 | linode/ 3 | -------------------------------------------------------------------------------- /deployment-scripts/README.md: -------------------------------------------------------------------------------- 1 | # Deployment Scripts for Multi-Service RTMP Broadcaster 2 | Here you will find deployment scripts for various cloud services. 3 | ## Linode 4 | [Sign up for Linode cloud hosting here](https://www.linode.com/?r=37246e0d6a6198293308e698647804fbfe02845e). 5 | 6 | The `linode-deploy.sh` shell script will create a Linode server, deploy the `multistreaming-server` docker image pulled from Docker Hub, and then launch the image using the JSON configuration file you specify. The `linode-cli` software should be installed on your local computer ([click here for instructions](https://www.linode.com/docs/platform/api/linode-cli/)). 7 | 8 | The script is run in the following manner: 9 | ``` 10 | RTMP_SERVER_LINODE_NODE_TYPE="g6-standard-6" \ 11 | ./linode-deploy.sh \ 12 | -c /path/to/rtmp-config.json \ 13 | -p secure-r00t-password \ 14 | -k ~/.ssh/id_rsa.pub \ 15 | -s stream_password 16 | ``` 17 | 18 | When running this script, it takes the following arguments: 19 | * `-c /path/to/config.json` - The file path the the JSON file containing the multistreaming server configuration. _REQUIRED_ 20 | * `-p root_password` - What the root password for the server being created should be set to. _REQUIRED_ 21 | * `-s stream_password` - The password that someone needs to use to push a stream to the rebroadcasting server. _REQUIRED_ 22 | * `-k /path/to/keyfile` - The file path to the public key file that should be used for keyless SSH connections to the server. If not specified, `~/.ssh/id_rsa.pub` will be used. Having a SSH key file defined on your system is _REQUIRED_. 23 | * `-h` - This will display more detailed information on how to use the script, including environment variables that are supported. 24 | 25 | If the script successfully completes, you will have a Linode server running with the Multi-Service RTMP Broadcaster software running. The script also prints some useful information and commands to use at the end of its run. Most notable is the server's IP address. This should be used in your streaming software configuration as described in [this project's README](https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/blob/master/README.md). 26 | 27 | There are several environment variables that control details of the type of server that will get deployed. Use the `-h` option to learn more. Two environment variables you might consider setting is the `RTMP_SERVER_LINODE_NODE_TYPE` variable to set the Linode type your server should use and `RTMP_SERVER_LINODE_REGION` variable to set the Linode region your server should reside. The Linode server type should have sufficient cores to handle the transcoding load required for your configuration. The Linode region should be the one closest to where you are streaming from. 28 | 29 | ## UpCloud 30 | [Sign up for UpCloud cloud hosting here](https://upcloud.com/signup/?promo=A2CVWA) 31 | 32 | This `upcloud-deploy.py` python script will create a server using the UpCloud service, deploy the `multistreaming-server` docker image pulled from Docker Hub, and then launch the image using the JSON configuration file you specify. The `upcloud-api` Python library must be installed on your local computer where you will run this script ([click here for instructions](https://github.com/UpCloudLtd/upcloud-python-api)). 33 | 34 | The script is run in the following manner: 35 | ``` 36 | RTMP_SERVER_UPCLOUD_NODE_CORES="2" RTMP_SERVER_UPCLOUD_NODE_RAM="2048" RTMP_SERVER_UPCLOUD_NODE_DISK="32" \ 37 | python3 upcloud-deploy.py \ 38 | -u upcloud_username -p upcloud_password \ 39 | -c /path/to/rtmp-config.json \ 40 | -k ~/.ssh/id_rsa.pub \ 41 | -s stream_password 42 | ``` 43 | When running this script, it takes the following arguments: 44 | * `-u ` - The user name for the UpCloud account that will be hosting the server. 45 | * `-p ` - The user password for the UpCloud account that will be hosting the server. 46 | * `-c /path/to/config.json` - The file path the the JSON file containing the multistreaming server configuration. _REQUIRED_ 47 | * `-k /path/to/ssh_key.pub` - The file path to the public key file that should be used for keyless SSH connections to the server. If not specified, `~/.ssh/id_rsa.pub` will be used. Having a SSH key file defined on your system is _REQUIRED_. 48 | * `-s stream_password` - The password that someone needs to use to push a stream to the rebroadcasting server. _REQUIRED_ 49 | * `-h` - This will display more detailed information on how to use the script, including environment variables that are supported. 50 | 51 | If the script successfully completes, you will have a UpCloud server running with the Multi-Service RTMP Broadcaster software running. The script also prints some useful information and commands to use at the end of its run. Most notable is the server's IP address. This should be used in your streaming software configuration as described in [this project's README](https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/blob/master/README.md). 52 | 53 | There are several environment variables that control details of the type of server that will get deployed. Use the `-h` option to learn more. The environment variables you might consider setting are `RTMP_SERVER_UPCLOUD_NODE_CORES` to indicate the number of cores your server will need, `RTMP_SERVER_UPCLOUD_NODE_RAM` to indicate how much RAM (in MB) your server will need, `RTMP_SERVER_UPCLOUD_NODE_DISK` to indicate the size of the disk (in GB) your server will need (note that all live streams get recorded on the server), and `RTMP_SERVER_UPCLOUD_REGION` to indicate what region your server should be deployed in ([possible values listed here](https://github.com/UpCloudLtd/upcloud-python-api/blob/master/upcloud_api/constants.py#L7)). 54 | 55 | ## Local Host 56 | 57 | Running the `multistreaming-server` locally is a great option if your local internet connection can support bandwidth required to push all of the rebroadcasted streams you intend to push. You should also consider if your local CPU should have sufficient cores to perform any transcoding you desire for individual streams. This script will simply launch a Docker container locally for the `multistreaming-server`. 58 | 59 | The script is run in the following manner: 60 | ``` 61 | ./local-deploy.sh \ 62 | -c /path/to/rtmp-config.json \ 63 | -s stream_password 64 | ``` 65 | 66 | When running this script, it takes the following arguments: 67 | * `-c /path/to/config.json` - The file path the the JSON file containing the multistreaming server configuration. _REQUIRED_ 68 | * `-s stream_password` - The password that someone needs to use to push a stream to the rebroadcasting server. _REQUIRED_ 69 | * `-b` - When present, the Docker image will be built locally (script assumes it has not been moved from this git repository). When not present, the docker image will be pull from Docker Hub. There are no arguments to option. 70 | * `-d` - Use to indicate the Docker image tag name that should be used for either the image built with the `-b` flag or pulled if `-b` is not present. If not present, the default image tag is `multistreaming-server:latest` for local builds using the `-b` option, and `kamprath/multistreaming-server:latest` if not building locally. It is recommended that this option does not get set and thus the default image tag values are used, but this option is provided if you "know what you are doing". 71 | * `-h` - This will display more detailed information on how to use the script, including environment variables that are supported. 72 | 73 | If the script successfully completes, you will be running a Docker container locally with the Multi-Service RTMP Broadcaster software running. The script also prints some useful information and commands to use at the end of its run. The IP address you should use to configure your streaming software's destination is `127.0.0.1` or `localhost`. 74 | 75 | ## Kubernetes 76 | 77 | You will find the required manifests to deploy the container to a Kubernetes cluster under the `./kubernetes-kustomize` directory. 78 | 79 | * Exposed RTMP/stats port: The example manifest in this repo will create a Service of type `NodePort` which will expose the RTMP endpoint on port 33195, and the stats endpoint on port 30080 on all the nodes. If you want to change this behavior, update `service.yaml` with the `nodePort` values you want. 80 | * Stream password: Stream password will be created a Kubernetes Secret in the cluster, to set the password open the file `kustomization.yaml` and find the entry with the name `multistreaming` in the list under the key `secretGenerator`. 81 | * RTMP Configuration JSON: The configuration file must be placed in the same path as the `kustomization.yaml` and should be named `rtmp-configuration.json`. The deployment will automatically read this file and create it in the cluster as a configmap. 82 | * Kubernetes namespace: By default the manifests will be deployed to a namespace called `multistreaming`. You may change this in `kustomization.yaml`. This namespace should be created manually before it can be used for deployments. 83 | 84 | Deployment command: 85 | ``` 86 | # Make sure you have your KUBECONFIG set. 87 | $ cd kubernetes-kustomize/ # or the path where you are storing the manifests 88 | $ kubectl create namespace multistreaming # the target namespace, should only be run once 89 | $ kubectl apply -k . # can be run many times to refresh the configuration 90 | ``` -------------------------------------------------------------------------------- /deployment-scripts/kubernetes-kustomize/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: multistreaming 5 | labels: 6 | app: multistreaming 7 | spec: 8 | selector: 9 | matchLabels: 10 | app: multistreaming 11 | template: 12 | metadata: 13 | labels: 14 | app: multistreaming 15 | spec: 16 | containers: 17 | - name: multistreaming 18 | image: kamprath/multistreaming-server:latest 19 | imagePullPolicy: Always 20 | volumeMounts: 21 | - name: config-volume 22 | mountPath: /rtmp-configuration.json 23 | subPath: rtmp-configuration.json 24 | env: 25 | - name: MULTISTREAMING_PASSWORD 26 | valueFrom: 27 | secretKeyRef: 28 | name: multistreaming 29 | key: password 30 | - name: CONFIG_NGINX_DEBUG 31 | value: "true" 32 | - name: CONFIG_FFMPEG_LOG 33 | value: "true" 34 | - name: CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE 35 | value: "4096" 36 | - name: CONFIG_DISABLE_RECORD 37 | value: "true" 38 | ports: 39 | - containerPort: 80 40 | - containerPort: 1935 41 | volumes: 42 | - name: config-volume 43 | configMap: 44 | name: multistreaming-config 45 | 46 | -------------------------------------------------------------------------------- /deployment-scripts/kubernetes-kustomize/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1beta1 2 | kind: Ingress 3 | metadata: 4 | name: multistreaming 5 | spec: 6 | rules: 7 | - host: multistreaming.ls90.co 8 | http: 9 | paths: 10 | - path: / 11 | backend: 12 | serviceName: multistreaming 13 | servicePort: 80 -------------------------------------------------------------------------------- /deployment-scripts/kubernetes-kustomize/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | nameSuffix: -v1 4 | namespace: multistreaming 5 | commonLabels: 6 | app: multistreaming 7 | version: v1 8 | resources: 9 | - deployment.yaml 10 | - service.yaml 11 | # - ingress.yaml # Optional, must configure the hostname if you need to expose the stat page as an ingress 12 | configMapGenerator: 13 | - name: multistreaming-config 14 | files: 15 | - rtmp-configuration.json 16 | secretGenerator: 17 | - name: multistreaming 18 | literals: 19 | - password=sekritPassword -------------------------------------------------------------------------------- /deployment-scripts/kubernetes-kustomize/rtmp-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "endpoint": "live", 3 | "transcodeProfiles": { 4 | "720_60fps": { 5 | "pixels": "1280x720", 6 | "videoBitRate": "4500k", 7 | "videoFrameRate": 60 8 | } 9 | }, 10 | "rebroadcastList": [ 11 | { 12 | "name": "twitch", 13 | "platform": "twitch", 14 | "streamKey": "foobar" 15 | }, 16 | { 17 | "name": "fbpage", 18 | "platform": "facebook", 19 | "streamKey": "secretKey", 20 | "transcodeProfile": "720_60fps" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /deployment-scripts/kubernetes-kustomize/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: multistreaming 5 | spec: 6 | selector: 7 | app: multistreaming 8 | type: NodePort 9 | ports: 10 | - name: web 11 | protocol: TCP 12 | port: 80 13 | targetPort: 80 14 | nodePort: 30080 15 | - name: rtmp 16 | protocol: TCP 17 | port: 1935 18 | targetPort: 1935 19 | nodePort: 31935 -------------------------------------------------------------------------------- /deployment-scripts/linode-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Assumes that the Linode CLI tool is already installed and enabled to create linodes. 5 | # 6 | 7 | # helper functions 8 | print_help_and_exit() 9 | { 10 | echo "Usage: " 11 | echo " linode-deploy.sh [-c /path/to/config.json] [-p ] [-k /path/to/ssh_key.pub] [-s ]" 12 | echo "" 13 | echo "Environment Variables (can be used instead of command arguments): " 14 | echo " RTMP_SERVER_CONFIG_FILEPATH : path to RTMP server config JSON file. Can replace -c option." 15 | echo " RTMP_SERVER_ROOTPW : Root password to be set for newly created Linode server. Can replace -p option." 16 | echo " RTMP_SERVER_AUTORIZED_KEY_FILE : SSH public key file path to enable secure connections for newly created Linode server. Defaults to ~/.ssh/id_rsa.pub. Can replace -k option." 17 | echo " RTMP_SERVER_STREAM_PASSWORD : Password used by RTMP streaming server for livestreams. Can replace -s option." 18 | echo " RTMP_SERVER_LINODE_REGION : Linode region to create server in. Defaults to 'us-west'." 19 | echo " RTMP_SERVER_LINODE_NODE_TYPE : Linode node type to use for server. Defaults to 'g6-standard-4'." 20 | echo "" 21 | exit 0 22 | } 23 | 24 | # check arguments passed to this script 25 | while getopts "c:p:k:s:h" option; do 26 | case "${option}" in 27 | c) 28 | RTMP_SERVER_CONFIG_FILEPATH=$OPTARG 29 | ;; 30 | p) 31 | RTMP_SERVER_ROOTPW=$OPTARG 32 | ;; 33 | k) 34 | RTMP_SERVER_AUTORIZED_KEY_FILE=$OPTARG 35 | ;; 36 | s) 37 | RTMP_SERVER_STREAM_PASSWORD=$OPTARG 38 | ;; 39 | h) 40 | print_help_and_exit 41 | ;; 42 | esac 43 | done 44 | shift $((OPTIND -1)) 45 | 46 | if [ -z $RTMP_SERVER_STREAM_PASSWORD ]; then 47 | echo "You must define a streaming password for the streaming server. Use the '-s' option or set the RTMP_SERVER_STREAM_PASSWORD environment variable." 48 | exit 2 49 | fi 50 | 51 | if [ -z $RTMP_SERVER_ROOTPW ]; then 52 | echo "You must define a root password for the server. Use the '-p' option or set the RTMP_SERVER_ROOTPW environement variable." 53 | exit 2 54 | fi 55 | 56 | if [ -z $RTMP_SERVER_CONFIG_FILEPATH ]; then 57 | echo "You must define a filepath to the streaming server configuration JSON file. Use the -c option." 58 | fi 59 | 60 | # Set variables to defaults if unset 61 | RTMP_SERVER_LINODE_REGION=${RTMP_SERVER_LINODE_REGION:-"us-west"} 62 | RTMP_SERVER_LINODE_NODE_TYPE=${RTMP_SERVER_LINODE_NODE_TYPE:-"g6-standard-4"} 63 | RTMP_SERVER_AUTORIZED_KEY_FILE=${RTMP_SERVER_AUTORIZED_KEY_FILE:-"~/.ssh/id_rsa.pub"} 64 | 65 | LINODE_DOCKER_SCRIPT_ID="607433" 66 | 67 | # launch a Docker server 68 | echo "Creating Linode server ..." 69 | linode_id=$( \ 70 | linode-cli linodes create \ 71 | --image "linode/debian9" \ 72 | --label multistreaming-server \ 73 | --authorized_keys "$(cat $RTMP_SERVER_AUTORIZED_KEY_FILE)" \ 74 | --root_pass "$RTMP_SERVER_ROOTPW" \ 75 | --booted true \ 76 | --region "$RTMP_SERVER_LINODE_REGION" \ 77 | --type "$RTMP_SERVER_LINODE_NODE_TYPE" \ 78 | --stackscript_id "$LINODE_DOCKER_SCRIPT_ID" \ 79 | --text --format 'id' --no-headers \ 80 | ) 81 | lindode_status=$(linode-cli linodes view ${linode_id} --text --format 'status' --no-headers) 82 | echo "Created Linode ${linode_id}. Current status is '${lindode_status}'. Waiting for it to transition to a running state." 83 | while [ $lindode_status != "running" ] 84 | do 85 | sleep 10 86 | lindode_status=$(linode-cli linodes view ${linode_id} --text --format 'status' --no-headers) 87 | echo "Linode ${linode_id} status is '${lindode_status}'." 88 | done 89 | linode_ip_addr=$(linode-cli linodes view ${linode_id} --text --format 'ipv4' --no-headers) 90 | echo "Linode ${linode_id} creation complete. IPv4 address is: ${linode_ip_addr}" 91 | echo "Waiting 5 minutes for booting and Docker installation to complete." 92 | sleep 60 93 | echo "Waiting 4 minutes for booting and Docker installation to complete." 94 | sleep 60 95 | echo "Waiting 3 minutes for booting and Docker installation to complete." 96 | sleep 60 97 | echo "Waiting 2 minutes for booting and Docker installation to complete." 98 | sleep 60 99 | echo "Waiting 1 minutes for booting and Docker installation to complete." 100 | sleep 60 101 | 102 | 103 | # Add IP address to known hosts so ssh commands can proceed unimpeded 104 | echo "Addding ${linode_ip_addr} to known_hosts" 105 | ssh-keygen -R ${linode_ip_addr} 106 | ssh-keyscan -T 240 ${linode_ip_addr} >> ~/.ssh/known_hosts 107 | 108 | # copy the passed RTMP server config file to the Server 109 | echo "Copying '${RTMP_SERVER_CONFIG_FILEPATH}' to path /root/rtmp_server_config.json on Linode ${linode_id}" 110 | scp -q "$RTMP_SERVER_CONFIG_FILEPATH" root@"${linode_ip_addr}":/root/rtmp_server_config.json 111 | if [ $? -ne 0 ]; then 112 | echo "ERROR - Unable to copy '${RTMP_SERVER_CONFIG_FILEPATH}' to linode ${linode_id}. Please terminate the Linode with this command:" 113 | echo " linode-cli linodes delete ${linode_id}" 114 | exit 1 115 | fi 116 | # now launch docker container 117 | echo "Launch kamprath/multistreaming-server:latest Docker image." 118 | docker_proc_id=$(ssh root@"$linode_ip_addr" \ 119 | "docker run -d -p 80:80 -p 1935:1935 " \ 120 | "--env MULTISTREAMING_PASSWORD=${RTMP_SERVER_STREAM_PASSWORD} " \ 121 | "-v /root/rtmp_server_config.json:/rtmp-configuration.json " \ 122 | "kamprath/multistreaming-server:latest" \ 123 | ) 124 | echo "Started Docker container: $docker_proc_id" 125 | # Finished 126 | echo "Finished!" 127 | echo "" 128 | echo "The IP address for the Multistreaming Server is:" 129 | echo " ${linode_ip_addr}" 130 | echo "" 131 | echo "Visit the Multistreaming Server's statistics page here:" 132 | echo " http://${linode_ip_addr}/stat" 133 | echo "" 134 | echo "Use this command to kill the server:" 135 | echo " linode-cli linodes delete ${linode_id}" 136 | echo "" 137 | echo "Use this command to log into the server:" 138 | echo " ssh root@${linode_ip_addr}" 139 | echo "" 140 | -------------------------------------------------------------------------------- /deployment-scripts/local-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | print_help_and_exit() 4 | { 5 | echo "Usage: " 6 | echo " local-deploy.sh [-c /path/to/config.json] [-s ] [-d ] [-b]" 7 | echo "" 8 | echo "Environment Variables (can be used instead of command arguments): " 9 | echo " RTMP_SERVER_CONFIG_FILEPATH : path to RTMP server config JSON file. Can replace -c option." 10 | echo " RTMP_SERVER_STREAM_PASSWORD : Password used by RTMP streaming server for livestreams. Can replace -s option." 11 | echo " RTMP_SERVER_DOCKER_IMAGE_NAME : The image name to pull from Docker hub, or the image name to use if building locally (-b)." 12 | exit 0 13 | } 14 | 15 | 16 | build_docker_image_locally() 17 | { 18 | # assumes this script is running in its original git repository. 19 | BASEDIR=$(dirname "$BASH_SOURCE") 20 | if [ $RTMP_SERVER_DOCKER_IMAGE_NAME == $DEFAULT_DOCKER_HUB_IMAGE_NAME ]; then 21 | RTMP_SERVER_DOCKER_IMAGE_NAME="multistreaming-server:latest" 22 | fi 23 | echo "Building Docker image '${RTMP_SERVER_DOCKER_IMAGE_NAME}'" 24 | docker build -t $RTMP_SERVER_DOCKER_IMAGE_NAME $BASEDIR/../multistreaming-server/ 25 | } 26 | 27 | DEFAULT_DOCKER_HUB_IMAGE_NAME="kamprath/multistreaming-server:latest" 28 | RTMP_SERVER_DOCKER_IMAGE_NAME=${RTMP_SERVER_DOCKER_IMAGE_NAME:-$DEFAULT_DOCKER_HUB_IMAGE_NAME} 29 | 30 | build_locally=false 31 | # check arguments passed to this script 32 | while getopts "c:s:d:bh" option; do 33 | case "${option}" in 34 | b) 35 | # By default this script pulls from Docker hub. This ooption 36 | # forces a local build of the Docker image. 37 | build_locally=true 38 | ;; 39 | c) 40 | RTMP_SERVER_CONFIG_FILEPATH=$OPTARG 41 | ;; 42 | s) 43 | RTMP_SERVER_STREAM_PASSWORD=$OPTARG 44 | ;; 45 | d) 46 | RTMP_SERVER_DOCKER_IMAGE_NAME=$OPTARG 47 | ;; 48 | h) 49 | print_help_and_exit 50 | ;; 51 | esac 52 | done 53 | shift $((OPTIND -1)) 54 | 55 | if [ -z $RTMP_SERVER_STREAM_PASSWORD ]; then 56 | echo "You must define a streaming password for the streaming server. Use the '-s' option or set the RTMP_SERVER_STREAM_PASSWORD environment variable." 57 | exit 2 58 | fi 59 | 60 | if [ -z $RTMP_SERVER_CONFIG_FILEPATH ]; then 61 | echo "You must define a filepath to the streaming server configuration JSON file. Use the -c option." 62 | fi 63 | 64 | # Build image if needed 65 | if [ "$build_locally" = true ]; then 66 | build_docker_image_locally 67 | fi 68 | 69 | # Launch the docker image 70 | config_file_absolute_path="$(cd "$(dirname "$RTMP_SERVER_CONFIG_FILEPATH")"; pwd)/$(basename "$RTMP_SERVER_CONFIG_FILEPATH")" 71 | echo "Launching $RTMP_SERVER_DOCKER_IMAGE_NAME Docker image with config at '${config_file_absolute_path}'." 72 | docker_proc_id=$( \ 73 | docker run -d -p 80:80 -p 1935:1935 \ 74 | --env MULTISTREAMING_PASSWORD=${RTMP_SERVER_STREAM_PASSWORD} \ 75 | -v "${config_file_absolute_path}":/rtmp-configuration.json \ 76 | ${RTMP_SERVER_DOCKER_IMAGE_NAME} \ 77 | ) 78 | docker_short_proc_id=$(echo $docker_proc_id | cut -c1-12) 79 | echo "" 80 | echo "Launched docker container $docker_short_proc_id. To stop this contianer:" 81 | echo " docker stop $docker_short_proc_id" 82 | echo "" 83 | echo "Visit the Multistreaming Server's statistics page here:" 84 | echo " http://127.0.0.1/stat" 85 | echo "" 86 | -------------------------------------------------------------------------------- /deployment-scripts/upcloud/.gitignore: -------------------------------------------------------------------------------- 1 | # virtual environment 2 | .venv 3 | -------------------------------------------------------------------------------- /deployment-scripts/upcloud/requirements.txt: -------------------------------------------------------------------------------- 1 | upcloud_api -------------------------------------------------------------------------------- /deployment-scripts/upcloud/upcloud-deploy.py: -------------------------------------------------------------------------------- 1 | # upcloud-deploy.py 2 | # 3 | # This python script deploys and instance of the Multiservice RTMP broadcaster 4 | # to a newly created server in the UpCloud hosting service. 5 | # 6 | # Assumes that the upcloud-api python library is installed. 7 | # Run with python3 8 | # 9 | import getopt 10 | import os 11 | import subprocess 12 | import sys 13 | import time 14 | 15 | import upcloud_api as up 16 | 17 | # This shell script is run on the server once the server is running. 18 | # It is used to install and configur Docker. 19 | INIT_SCRIPT = """ 20 | # Update the system and install useful packages 21 | apt-get update 22 | apt-get upgrade -y 23 | apt-get install htop 24 | 25 | # Install docker 26 | curl -fsSL https://get.docker.com -o get-docker.sh 27 | sh get-docker.sh 28 | 29 | # Enable firewall 30 | ufw enable 31 | ufw allow 22 32 | ufw allow http 33 | ufw allow 1935 34 | 35 | # configure the rtmpserver user 36 | usermod -a -G docker rtmpserver 37 | 38 | """ 39 | 40 | def print_help(): 41 | print( 42 | 'Example usage:\n ' 43 | 'python3 upcloud-deploy.py ' 44 | '-u ' 45 | '-p ' 46 | '-c /path/to/config.json ' 47 | '-k /path/to/ssh_key.pub ' 48 | '-s ' 49 | '\n' 50 | ) 51 | print('Environment Variables (can be used instead of command arguments):') 52 | print(' RTMP_SERVER_UPCLOUD_USER : UpCloud user name to authenticate with. Can replace \'-u\' option.') 53 | print(' RTMP_SERVER_UPCLOUD_PASSWORD : UpCloud user password to authenticate with. Can replace \'-p\' option.') 54 | print(' RTMP_SERVER_UPCLOUD_REGION : UpCloud region to create server in. Defaults to \'us-sjo1\'.') 55 | print(' RTMP_SERVER_UPCLOUD_NODE_CORES : The number cores for the UpCloud server. Defaults to \'4\'') 56 | print(' RTMP_SERVER_UPCLOUD_NODE_RAM : The amount of RAM in MB for the UpCloud server. Defaults to \'4096\'') 57 | print(' RTMP_SERVER_UPCLOUD_NODE_DISK : The amount of disk space in GB for the UpCloud server. Defaults to \'64\'') 58 | 59 | # Default values for config 60 | upcloud_user = None \ 61 | if 'RTMP_SERVER_UPCLOUD_USER' not in os.environ \ 62 | else os.environ['RTMP_SERVER_UPCLOUD_USER'] 63 | upcloud_password = None \ 64 | if 'RTMP_SERVER_UPCLOUD_PASSWORD' not in os.environ \ 65 | else os.environ['RTMP_SERVER_UPCLOUD_PASSWORD'] 66 | upcloud_region = up.ZONE.SanJose \ 67 | if 'RTMP_SERVER_UPCLOUD_REGION' not in os.environ \ 68 | else os.environ['RTMP_SERVER_UPCLOUD_REGION'] 69 | upcloud_cores = 4 \ 70 | if 'RTMP_SERVER_UPCLOUD_NODE_CORES' not in os.environ \ 71 | else int(os.environ['RTMP_SERVER_UPCLOUD_NODE_CORES']) 72 | upcloud_ram = 4096 \ 73 | if 'RTMP_SERVER_UPCLOUD_NODE_RAM' not in os.environ \ 74 | else int(os.environ['RTMP_SERVER_UPCLOUD_NODE_RAM']) 75 | upcloud_disk = 64 \ 76 | if 'RTMP_SERVER_UPCLOUD_NODE_DISK' not in os.environ \ 77 | else int(os.environ['RTMP_SERVER_UPCLOUD_NODE_DISK']) 78 | rtmp_config_filepath = None 79 | ssh_key_filepath = '~/.ssh/id_rsa.pub' 80 | rtmp_streaming_password = None 81 | 82 | # fetch CLI arguments 83 | try: 84 | opts, args = getopt.getopt(sys.argv[1:],"u:p:c:k:s:h") 85 | except getopt.GetoptError as err: 86 | print(err) 87 | print_help() 88 | exit(2) 89 | 90 | for opt, arg in opts: 91 | if opt == '-u': 92 | upcloud_user = arg 93 | elif opt == '-p': 94 | upcloud_password = arg 95 | elif opt == '-c': 96 | rtmp_config_filepath = arg 97 | elif opt == '-k': 98 | ssh_key_filepath = arg 99 | elif opt == '-s': 100 | rtmp_streaming_password = arg 101 | elif opt == '-h': 102 | print_help() 103 | exit(0) 104 | else: 105 | print('ERROR - Got on unrecognized command line option "{0}"'.format(opt)) 106 | exit(2) 107 | 108 | if upcloud_user is None \ 109 | or upcloud_password is None \ 110 | or rtmp_config_filepath is None \ 111 | or ssh_key_filepath is None \ 112 | or rtmp_streaming_password is None: 113 | print('ERROR - configuration is not complete.') 114 | exit(2) 115 | 116 | # Connect to UpCloud 117 | manager = up.CloudManager(upcloud_user, upcloud_password, timeout=60) 118 | manager.authenticate() 119 | print('Connected to UpCloud API as user "{0}"'.format(upcloud_user)) 120 | 121 | res = subprocess.run( 122 | 'cat {0}'.format(ssh_key_filepath), 123 | shell=True, 124 | stdout=subprocess.PIPE, 125 | text=True, 126 | ) 127 | ssh_key_value = res.stdout.strip() 128 | rtmp_user_desc = up.login_user_block( 129 | username='rtmpserver', 130 | ssh_keys=[ssh_key_value], 131 | create_password=False, 132 | ) 133 | 134 | rtmp_server_desc = up.Server( 135 | core_number=upcloud_cores, # CPU cores 136 | memory_amount=upcloud_ram, # RAM in MB 137 | zone=upcloud_region, 138 | title='Multiservice RTMP Broadcaster', 139 | # UpCloud strangely requires that every server have a qualified domain 140 | # name. (?!) Using a totaly made up name here. 141 | hostname='multiservice-rtmp-server.com', 142 | storage_devices=[ 143 | up.Storage(os='Ubuntu 18.04', size=upcloud_disk ), 144 | ], 145 | login_user=rtmp_user_desc, # user and ssh-keys 146 | user_data=INIT_SCRIPT, 147 | ) 148 | 149 | print('Starting creation of server with these parameters:') 150 | print( 151 | ' cores = {0}\n' 152 | ' RAM = {1} MB\n' 153 | ' disk = {2} GB\n' 154 | ' region = {3}'.format( 155 | upcloud_cores, upcloud_ram, upcloud_disk, upcloud_region 156 | ) 157 | ) 158 | rtmp_server = manager.create_server(rtmp_server_desc) 159 | ip_addr = rtmp_server.get_ip() 160 | print( 161 | 'Server creation done.\n' 162 | ' server = {0}\n' 163 | ' IP address = {1}'.format(rtmp_server, ip_addr) 164 | ) 165 | 166 | # wait for the server to finish booting and installing docker 167 | print('Waiting 8 minutes for server set up to complete ...') 168 | time.sleep(60) 169 | print('Waiting 7 minutes for server set up to complete ...') 170 | time.sleep(60) 171 | print('Waiting 6 minutes for server set up to complete ...') 172 | time.sleep(60) 173 | print('Waiting 5 minutes for server set up to complete ...') 174 | time.sleep(60) 175 | print('Waiting 4 minutes for server set up to complete ...') 176 | time.sleep(60) 177 | print('Waiting 3 minutes for server set up to complete ...') 178 | time.sleep(60) 179 | print('Waiting 2 minutes for server set up to complete ...') 180 | time.sleep(60) 181 | print('Waiting 1 minutes for server set up to complete ...') 182 | time.sleep(60) 183 | 184 | # Send configuration to server and launch Docker image 185 | print('Adding IP address {0} to known hosts ...'.format(ip_addr)) 186 | res = subprocess.run('ssh-keygen -R {}'.format(ip_addr), shell=True) 187 | if res.returncode != 0: 188 | print('ERROR when removing server IP from known hosts.\n {0}'.format(res.stderr)) 189 | exit(1) 190 | elif res.stdout is not None: 191 | print(res.stdout) 192 | res = subprocess.run('ssh-keyscan -T 240 {0} >> ~/.ssh/known_hosts'.format(ip_addr), shell=True) 193 | if res.returncode != 0: 194 | print('ERROR when adding server IP to known hosts.\n {0}'.format(res.stderr)) 195 | exit(1) 196 | elif res.stdout is not None: 197 | print(res.stdout) 198 | 199 | # send configuration file to Server 200 | scp_cmd = 'scp \'{0}\' rtmpserver@{1}:/home/rtmpserver/rtmp_server_config.json'.format( 201 | rtmp_config_filepath, 202 | ip_addr 203 | ) 204 | print('Sending configuration file to serverr with: {0}'.format(scp_cmd)) 205 | res = subprocess.run( 206 | scp_cmd, 207 | shell=True 208 | ) 209 | if res.returncode != 0: 210 | print( 211 | 'ERROR when sending RTMP configuration to server.\n' 212 | ' returncode = {0}\n stderr = {1}'.format(res.returncode, res.stderr) 213 | ) 214 | exit(1) 215 | elif res.stdout is not None: 216 | print(res.stdout) 217 | 218 | # start the docker subprocess 219 | res = subprocess.run( 220 | 'ssh rtmpserver@{0} ' 221 | '"docker run -d -p 80:80 -p 1935:1935 ' 222 | '--env MULTISTREAMING_PASSWORD={1} ' 223 | '-v /home/rtmpserver/rtmp_server_config.json:/rtmp-configuration.json ' 224 | 'kamprath/multistreaming-server:latest"'.format( 225 | ip_addr, rtmp_streaming_password 226 | ), 227 | shell=True, 228 | stdout=subprocess.PIPE, 229 | text=True, 230 | ) 231 | docker_container_id = res.stdout[:12] 232 | print('Started Docker container: {0}'.format(docker_container_id)) 233 | 234 | # Finished 235 | print('Finished!\n') 236 | print('The IP address for the Multistreaming Server is:') 237 | print(' {0}\n'.format(ip_addr)) 238 | print('Visit the Multistreaming Server\'s statistics page here:') 239 | print(' http://{0}/stat\n'.format(ip_addr)) 240 | print('Use this command to log into the server (if needed):') 241 | print(' ssh rtmpserver@{0}\n'.format(ip_addr)) 242 | print('When done, terminate this server in the UpCloud Web Console here:') 243 | print(' https://hub.upcloud.com/\n') 244 | -------------------------------------------------------------------------------- /multistreaming-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jrottenberg/ffmpeg:5-alpine 2 | MAINTAINER Michael Kamprath "https://github.com/michaelkamprath" 3 | 4 | ARG NGINX_VERSION=1.20.0 5 | ARG RTMP_REPO=uizaio 6 | ARG RTMP_MODULE_VERSION=1.4.0.4 7 | ARG TINI_VERSION=v0.19.0 8 | ARG SUPERVISORD_VERSION=4.2.4 9 | ARG PIPENV_PACKAGE_VERSION=2022.1.8 10 | 11 | RUN set -x \ 12 | && addgroup -S stunnel \ 13 | && adduser -S -D -H -h /dev/null -s /sbin/nologin -G stunnel -g stunnel stunnel \ 14 | && echo "//dl-cdn.alpinelinux.org/alpine/latest-stable/main/x86_64/" >> /etc/apk/repositories \ 15 | && apk update \ 16 | && apk add --no-cache --update stunnel ca-certificates \ 17 | && apk add --no-cache pcre openssl stunnel gettext python3 py3-pip \ 18 | && apk add --no-cache --virtual build-deps build-base pcre-dev openssl-dev zlib zlib-dev wget make \ 19 | && wget -O nginx-${NGINX_VERSION}.tar.gz http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \ 20 | && tar -zxvf nginx-${NGINX_VERSION}.tar.gz \ 21 | && wget -O nginx-rtmp-module-${RTMP_MODULE_VERSION}.tar.gz https://github.com/${RTMP_REPO}/nginx-rtmp-module/archive/${RTMP_MODULE_VERSION}.tar.gz \ 22 | && tar -zxvf nginx-rtmp-module-${RTMP_MODULE_VERSION}.tar.gz \ 23 | && cd nginx-${NGINX_VERSION} \ 24 | && export CFLAGS=-Wno-error \ 25 | && ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-${RTMP_MODULE_VERSION} \ 26 | && make \ 27 | && make install \ 28 | && cp /nginx-rtmp-module-${RTMP_MODULE_VERSION}/stat.xsl /usr/local/nginx/html/ \ 29 | && apk del build-deps \ 30 | && mkdir -p /var/www/html/recordings \ 31 | && mkdir -p /var/run/stunnel/ \ 32 | && chown nobody:nobody -R /var/www/html \ 33 | && chown stunnel:stunnel /var/run/stunnel/ \ 34 | && wget -O /tini https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static \ 35 | && chmod +x /tini \ 36 | && pip3 install --ignore-installed distlib supervisor==${SUPERVISORD_VERSION} pipenv==${PIPENV_PACKAGE_VERSION} 37 | 38 | COPY Pipfile Pipfile.lock / 39 | RUN pipenv install --system --deploy 40 | 41 | COPY supervisord.conf /etc/supervisor/supervisord.conf 42 | COPY stunnel-conf/etc-default-stunnel /etc/default/stunnel 43 | COPY stunnel-conf/etc-stunnel-conf.d-fb.conf /etc/stunnel/conf.d/fb.conf 44 | COPY stunnel-conf/etc-stunnel-conf.d-ig.conf /etc/stunnel/conf.d/ig.conf 45 | COPY stunnel-conf/etc-stunnel-stunnel.conf /etc/stunnel/stunnel.conf 46 | 47 | COPY index.html /usr/local/nginx/html/ 48 | COPY nginx-conf/nginx.conf /base-nginx.conf 49 | COPY launch-nginx-server.sh launch-nginx-server.sh 50 | COPY rtmp-conf-generator.py nginx-template.conf.j2 / 51 | RUN touch /rtmp-configuration.json && chmod 744 /rtmp-configuration.json 52 | 53 | EXPOSE 1935 54 | EXPOSE 80 55 | 56 | STOPSIGNAL SIGTERM 57 | ENTRYPOINT ["/tini", "--"] 58 | CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] 59 | -------------------------------------------------------------------------------- /multistreaming-server/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | pylint = "*" 8 | black = "*" 9 | 10 | [packages] 11 | jinja2 = "*" 12 | 13 | [requires] 14 | python_version = "3.12" 15 | 16 | [pipenv] 17 | allow_prereleases = true 18 | -------------------------------------------------------------------------------- /multistreaming-server/Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "999482fdcf4ef4a48be7cfc160df6000b69546a4c9d77be01e8c5b1b4e23be77" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": { 8 | "python_version": "3.12" 9 | }, 10 | "sources": [ 11 | { 12 | "name": "pypi", 13 | "url": "https://pypi.org/simple", 14 | "verify_ssl": true 15 | } 16 | ] 17 | }, 18 | "default": { 19 | "jinja2": { 20 | "hashes": [ 21 | "sha256:8fefff8dc3034e27bb80d67c671eb8a9bc424c0ef4c0826edbff304cceff43bb", 22 | "sha256:aba0f4dc9ed8013c424088f68a5c226f7d6097ed89b246d7749c2ec4175c6adb" 23 | ], 24 | "index": "pypi", 25 | "markers": "python_version >= '3.7'", 26 | "version": "==3.1.5" 27 | }, 28 | "markupsafe": { 29 | "hashes": [ 30 | "sha256:0bff5e0ae4ef2e1ae4fdf2dfd5b76c75e5c2fa4132d05fc1b0dabcd20c7e28c4", 31 | "sha256:0f4ca02bea9a23221c0182836703cbf8930c5e9454bacce27e767509fa286a30", 32 | "sha256:1225beacc926f536dc82e45f8a4d68502949dc67eea90eab715dea3a21c1b5f0", 33 | "sha256:131a3c7689c85f5ad20f9f6fb1b866f402c445b220c19fe4308c0b147ccd2ad9", 34 | "sha256:15ab75ef81add55874e7ab7055e9c397312385bd9ced94920f2802310c930396", 35 | "sha256:1a9d3f5f0901fdec14d8d2f66ef7d035f2157240a433441719ac9a3fba440b13", 36 | "sha256:1c99d261bd2d5f6b59325c92c73df481e05e57f19837bdca8413b9eac4bd8028", 37 | "sha256:1e084f686b92e5b83186b07e8a17fc09e38fff551f3602b249881fec658d3eca", 38 | "sha256:2181e67807fc2fa785d0592dc2d6206c019b9502410671cc905d132a92866557", 39 | "sha256:2cb8438c3cbb25e220c2ab33bb226559e7afb3baec11c4f218ffa7308603c832", 40 | "sha256:3169b1eefae027567d1ce6ee7cae382c57fe26e82775f460f0b2778beaad66c0", 41 | "sha256:3809ede931876f5b2ec92eef964286840ed3540dadf803dd570c3b7e13141a3b", 42 | "sha256:38a9ef736c01fccdd6600705b09dc574584b89bea478200c5fbf112a6b0d5579", 43 | "sha256:3d79d162e7be8f996986c064d1c7c817f6df3a77fe3d6859f6f9e7be4b8c213a", 44 | "sha256:444dcda765c8a838eaae23112db52f1efaf750daddb2d9ca300bcae1039adc5c", 45 | "sha256:48032821bbdf20f5799ff537c7ac3d1fba0ba032cfc06194faffa8cda8b560ff", 46 | "sha256:4aa4e5faecf353ed117801a068ebab7b7e09ffb6e1d5e412dc852e0da018126c", 47 | "sha256:52305740fe773d09cffb16f8ed0427942901f00adedac82ec8b67752f58a1b22", 48 | "sha256:569511d3b58c8791ab4c2e1285575265991e6d8f8700c7be0e88f86cb0672094", 49 | "sha256:57cb5a3cf367aeb1d316576250f65edec5bb3be939e9247ae594b4bcbc317dfb", 50 | "sha256:5b02fb34468b6aaa40dfc198d813a641e3a63b98c2b05a16b9f80b7ec314185e", 51 | "sha256:6381026f158fdb7c72a168278597a5e3a5222e83ea18f543112b2662a9b699c5", 52 | "sha256:6af100e168aa82a50e186c82875a5893c5597a0c1ccdb0d8b40240b1f28b969a", 53 | "sha256:6c89876f41da747c8d3677a2b540fb32ef5715f97b66eeb0c6b66f5e3ef6f59d", 54 | "sha256:6e296a513ca3d94054c2c881cc913116e90fd030ad1c656b3869762b754f5f8a", 55 | "sha256:70a87b411535ccad5ef2f1df5136506a10775d267e197e4cf531ced10537bd6b", 56 | "sha256:7e94c425039cde14257288fd61dcfb01963e658efbc0ff54f5306b06054700f8", 57 | "sha256:846ade7b71e3536c4e56b386c2a47adf5741d2d8b94ec9dc3e92e5e1ee1e2225", 58 | "sha256:88416bd1e65dcea10bc7569faacb2c20ce071dd1f87539ca2ab364bf6231393c", 59 | "sha256:88b49a3b9ff31e19998750c38e030fc7bb937398b1f78cfa599aaef92d693144", 60 | "sha256:8c4e8c3ce11e1f92f6536ff07154f9d49677ebaaafc32db9db4620bc11ed480f", 61 | "sha256:8e06879fc22a25ca47312fbe7c8264eb0b662f6db27cb2d3bbbc74b1df4b9b87", 62 | "sha256:9025b4018f3a1314059769c7bf15441064b2207cb3f065e6ea1e7359cb46db9d", 63 | "sha256:93335ca3812df2f366e80509ae119189886b0f3c2b81325d39efdb84a1e2ae93", 64 | "sha256:9778bd8ab0a994ebf6f84c2b949e65736d5575320a17ae8984a77fab08db94cf", 65 | "sha256:9e2d922824181480953426608b81967de705c3cef4d1af983af849d7bd619158", 66 | "sha256:a123e330ef0853c6e822384873bef7507557d8e4a082961e1defa947aa59ba84", 67 | "sha256:a904af0a6162c73e3edcb969eeeb53a63ceeb5d8cf642fade7d39e7963a22ddb", 68 | "sha256:ad10d3ded218f1039f11a75f8091880239651b52e9bb592ca27de44eed242a48", 69 | "sha256:b424c77b206d63d500bcb69fa55ed8d0e6a3774056bdc4839fc9298a7edca171", 70 | "sha256:b5a6b3ada725cea8a5e634536b1b01c30bcdcd7f9c6fff4151548d5bf6b3a36c", 71 | "sha256:ba8062ed2cf21c07a9e295d5b8a2a5ce678b913b45fdf68c32d95d6c1291e0b6", 72 | "sha256:ba9527cdd4c926ed0760bc301f6728ef34d841f405abf9d4f959c478421e4efd", 73 | "sha256:bbcb445fa71794da8f178f0f6d66789a28d7319071af7a496d4d507ed566270d", 74 | "sha256:bcf3e58998965654fdaff38e58584d8937aa3096ab5354d493c77d1fdd66d7a1", 75 | "sha256:c0ef13eaeee5b615fb07c9a7dadb38eac06a0608b41570d8ade51c56539e509d", 76 | "sha256:cabc348d87e913db6ab4aa100f01b08f481097838bdddf7c7a84b7575b7309ca", 77 | "sha256:cdb82a876c47801bb54a690c5ae105a46b392ac6099881cdfb9f6e95e4014c6a", 78 | "sha256:cfad01eed2c2e0c01fd0ecd2ef42c492f7f93902e39a42fc9ee1692961443a29", 79 | "sha256:d16a81a06776313e817c951135cf7340a3e91e8c1ff2fac444cfd75fffa04afe", 80 | "sha256:d8213e09c917a951de9d09ecee036d5c7d36cb6cb7dbaece4c71a60d79fb9798", 81 | "sha256:e07c3764494e3776c602c1e78e298937c3315ccc9043ead7e685b7f2b8d47b3c", 82 | "sha256:e17c96c14e19278594aa4841ec148115f9c7615a47382ecb6b82bd8fea3ab0c8", 83 | "sha256:e444a31f8db13eb18ada366ab3cf45fd4b31e4db1236a4448f68778c1d1a5a2f", 84 | "sha256:e6a2a455bd412959b57a172ce6328d2dd1f01cb2135efda2e4576e8a23fa3b0f", 85 | "sha256:eaa0a10b7f72326f1372a713e73c3f739b524b3af41feb43e4921cb529f5929a", 86 | "sha256:eb7972a85c54febfb25b5c4b4f3af4dcc731994c7da0d8a0b4a6eb0640e1d178", 87 | "sha256:ee55d3edf80167e48ea11a923c7386f4669df67d7994554387f84e7d8b0a2bf0", 88 | "sha256:f3818cb119498c0678015754eba762e0d61e5b52d34c8b13d770f0719f7b1d79", 89 | "sha256:f8b3d067f2e40fe93e1ccdd6b2e1d16c43140e76f02fb1319a05cf2b79d99430", 90 | "sha256:fcabf5ff6eea076f859677f5f0b6b5c1a51e70a376b0579e0eadef8db48c6b50" 91 | ], 92 | "markers": "python_version >= '3.9'", 93 | "version": "==3.0.2" 94 | } 95 | }, 96 | "develop": { 97 | "astroid": { 98 | "hashes": [ 99 | "sha256:0e14202810b30da1b735827f78f5157be2bbd4a7a59b7707ca0bfc2fb4c0063a", 100 | "sha256:413658a61eeca6202a59231abb473f932038fbcbf1666587f66d482083413a25" 101 | ], 102 | "markers": "python_full_version >= '3.8.0'", 103 | "version": "==3.2.4" 104 | }, 105 | "black": { 106 | "hashes": [ 107 | "sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6", 108 | "sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e", 109 | "sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f", 110 | "sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018", 111 | "sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e", 112 | "sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd", 113 | "sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4", 114 | "sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed", 115 | "sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2", 116 | "sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42", 117 | "sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af", 118 | "sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb", 119 | "sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368", 120 | "sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb", 121 | "sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af", 122 | "sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed", 123 | "sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47", 124 | "sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2", 125 | "sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a", 126 | "sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c", 127 | "sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920", 128 | "sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1" 129 | ], 130 | "index": "pypi", 131 | "markers": "python_version >= '3.8'", 132 | "version": "==24.8.0" 133 | }, 134 | "click": { 135 | "hashes": [ 136 | "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28", 137 | "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de" 138 | ], 139 | "markers": "python_version >= '3.7'", 140 | "version": "==8.1.7" 141 | }, 142 | "dill": { 143 | "hashes": [ 144 | "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca", 145 | "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7" 146 | ], 147 | "markers": "python_version >= '3.11'", 148 | "version": "==0.3.8" 149 | }, 150 | "isort": { 151 | "hashes": [ 152 | "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109", 153 | "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6" 154 | ], 155 | "markers": "python_full_version >= '3.8.0'", 156 | "version": "==5.13.2" 157 | }, 158 | "mccabe": { 159 | "hashes": [ 160 | "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", 161 | "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e" 162 | ], 163 | "markers": "python_version >= '3.6'", 164 | "version": "==0.7.0" 165 | }, 166 | "mypy-extensions": { 167 | "hashes": [ 168 | "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", 169 | "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782" 170 | ], 171 | "markers": "python_version >= '3.5'", 172 | "version": "==1.0.0" 173 | }, 174 | "packaging": { 175 | "hashes": [ 176 | "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002", 177 | "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124" 178 | ], 179 | "markers": "python_version >= '3.8'", 180 | "version": "==24.1" 181 | }, 182 | "pathspec": { 183 | "hashes": [ 184 | "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", 185 | "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712" 186 | ], 187 | "markers": "python_version >= '3.8'", 188 | "version": "==0.12.1" 189 | }, 190 | "platformdirs": { 191 | "hashes": [ 192 | "sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907", 193 | "sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb" 194 | ], 195 | "markers": "python_version >= '3.8'", 196 | "version": "==4.3.6" 197 | }, 198 | "pylint": { 199 | "hashes": [ 200 | "sha256:02f4aedeac91be69fb3b4bea997ce580a4ac68ce58b89eaefeaf06749df73f4b", 201 | "sha256:1b7a721b575eaeaa7d39db076b6e7743c993ea44f57979127c517c6c572c803e" 202 | ], 203 | "index": "pypi", 204 | "markers": "python_full_version >= '3.8.0'", 205 | "version": "==3.2.7" 206 | }, 207 | "tomlkit": { 208 | "hashes": [ 209 | "sha256:7a974427f6e119197f670fbbbeae7bef749a6c14e793db934baefc1b5f03efde", 210 | "sha256:fff5fe59a87295b278abd31bec92c15d9bc4a06885ab12bcea52c71119392e79" 211 | ], 212 | "markers": "python_version >= '3.8'", 213 | "version": "==0.13.2" 214 | } 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /multistreaming-server/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Multistream Server

6 |

This service is being used to rebroadcast livestreams to multiple services.

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /multistreaming-server/launch-nginx-server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # set the password from environment variable 4 | export DOLLAR='$' 5 | envsubst < base-nginx.conf > /usr/local/nginx/conf/nginx.conf 6 | 7 | # append nginx conf with RTMP Configuration 8 | python3 /rtmp-conf-generator.py /rtmp-configuration.json /nginx-template.conf.j2 >> /usr/local/nginx/conf/nginx.conf 9 | if [ $? -ne 0 ]; then 10 | echo "ERROR encountered when generating RTMP configuration." 11 | exit 1 12 | fi 13 | 14 | # finally, launch nginx 15 | /usr/local/nginx/sbin/nginx -g "daemon off;" 16 | -------------------------------------------------------------------------------- /multistreaming-server/nginx-conf/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 1; 2 | 3 | events { 4 | worker_connections 1024; 5 | } 6 | 7 | http { 8 | include mime.types; 9 | default_type application/octet-stream; 10 | 11 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 12 | # '$status $body_bytes_sent "$http_referer" ' 13 | # '"$http_user_agent" "$http_x_forwarded_for"'; 14 | 15 | access_log /dev/stdout; 16 | 17 | sendfile on; 18 | #tcp_nopush on; 19 | 20 | #keepalive_timeout 0; 21 | keepalive_timeout 65; 22 | 23 | #gzip on; 24 | 25 | server { 26 | listen 80; 27 | server_name 127.0.0.1; 28 | 29 | #charset koi8-r; 30 | 31 | #access_log logs/host.access.log main; 32 | 33 | location / { 34 | root html; 35 | index index.html index.htm; 36 | } 37 | 38 | location /auth { 39 | if (${DOLLAR}arg_pwd = '${MULTISTREAMING_PASSWORD}') { 40 | return 200; 41 | } 42 | return 401; 43 | } 44 | 45 | # This URL provides RTMP statistics in XML 46 | location /stat { 47 | rtmp_stat all; 48 | 49 | # Use this stylesheet to view XML as web page 50 | # in browser 51 | rtmp_stat_stylesheet stat.xsl; 52 | } 53 | 54 | location /stat.xsl { 55 | # XML stylesheet to view RTMP stats. 56 | # Copy stat.xsl wherever you want 57 | # and put the full directory path here 58 | root /usr/local/nginx/html/; 59 | } 60 | 61 | 62 | #error_page 404 /404.html; 63 | 64 | # redirect server error pages to the static page /50x.html 65 | # 66 | error_page 500 502 503 504 /50x.html; 67 | location = /50x.html { 68 | root html; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /multistreaming-server/nginx-template.conf.j2: -------------------------------------------------------------------------------- 1 | {% if nginx_error_log %} error_log /dev/stderr debug; {% endif %} 2 | 3 | rtmp { 4 | server { 5 | listen 1935; 6 | chunk_size 4096; 7 | notify_method get; 8 | 9 | application {{ endpoint_name }} { 10 | on_publish http://127.0.0.1/auth; 11 | live on; 12 | record {{ record_mode }}; 13 | record_path /var/www/html/recordings; 14 | record_unique on; 15 | 16 | # Define the applications to which the stream will be pushed, comment them out to disable the ones not needed: 17 | {% for name in transcode_configs.keys() %} 18 | push rtmp://127.0.0.1:1935/transcode_{{name}}; 19 | {% endfor %} 20 | {% for application_endpoint in push_only_applications %} 21 | push rtmp://127.0.0.1:1935/{{application_endpoint}}; 22 | {% endfor %} 23 | } 24 | 25 | # transcode definitions 26 | {% for name, transcode_config in transcode_configs.items() %} 27 | application transcode_{{name}} { 28 | live on; 29 | record off; 30 | 31 | # Only allow 127.0.0.1 to publish 32 | allow publish 127.0.0.1; 33 | deny publish all; 34 | 35 | # need to transcode 36 | exec ffmpeg -re -i rtmp://127.0.0.1:1935/$app/$name 37 | -c:v libx264 38 | -s {{transcode_config['pixels']}} 39 | -b:v {{transcode_config['videoBitRate']}} 40 | -bufsize 12M 41 | -r {{transcode_config['videoFrameRate']}} 42 | -x264opts "keyint={{transcode_config['keyFrames']}}:min-keyint={{transcode_config['keyFrames']}}:no-scenecut:nal-hrd=cbr" 43 | {{transcode_config['audioOpts']}} 44 | {% if transcode_config['maxMuxingQueueSize'] %}-max_muxing_queue_size {{transcode_config['maxMuxingQueueSize']}}{% endif %} 45 | -f flv rtmp://127.0.0.1:1935/transcode_output_{{name}}/$name 46 | {% if transcode_config['logFfmpeg'] %} 2>>/tmp/ffmpeg-{{name}}.log {% endif %} 47 | ; 48 | } 49 | 50 | application transcode_output_{{name}} { 51 | live on; 52 | record off; 53 | 54 | # Only allow 127.0.0.1 to publish 55 | allow publish 127.0.0.1; 56 | deny publish all; 57 | 58 | {% for application_endpoint in transcode_config['applicationEndpoints'] %} 59 | push rtmp://127.0.0.1:1935/{{application_endpoint}}; 60 | {% endfor %} 61 | } 62 | {% endfor %} 63 | 64 | # application defintions 65 | {% for name, application_config in application_configs.items() %} 66 | application {{ name }} { 67 | live on; 68 | record off; 69 | 70 | # Only allow 127.0.0.1 to publish 71 | allow publish 127.0.0.1; 72 | deny publish all; 73 | 74 | # Push URL 75 | push {{ application_config['pushUrl'] }}; 76 | } 77 | {% endfor %} 78 | } 79 | } -------------------------------------------------------------------------------- /multistreaming-server/rtmp-conf-generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import copy 4 | import jinja2 5 | import json 6 | import os 7 | import re 8 | import sys 9 | 10 | # 11 | # Configurable ENV VARS 12 | # 13 | 14 | CONFIG_NGINX_DEBUG = os.getenv('CONFIG_NGINX_DEBUG', False) 15 | CONFIG_FFMPEG_LOG = os.getenv('CONFIG_FFMPEG_LOG', False) 16 | CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE = os.getenv( 17 | 'CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE', False 18 | ) 19 | CONFIG_DISABLE_RECORD = os.getenv('CONFIG_DISABLE_RECORD', False) 20 | 21 | # 22 | # Defaults 23 | # 24 | 25 | RTMP_TRANSCODE_AUDIO_OPTS_COPY = '-c:a copy' 26 | RTMP_TRANSCODE_AUDIO_OPTS_CUSTOM = ( 27 | '-c:a libfdk_aac -b:a %%AUDIO_BIT_RATE%% -ar %%AUDIO_SAMPLE_RATE%%' 28 | ) 29 | 30 | # https://support.restream.io/en/articles/73108-best-settings 31 | PUSH_URL_RESTREAM = 'rtmp://live.restream.io/live/%%STREAM_KEY%%' # Restream let's you stream to LinkedIn Live 32 | PUSH_URL_YOUTUBE = 'rtmp://a.rtmp.youtube.com/live2/%%STREAM_KEY%%' 33 | PUSH_URL_FACEBOOK = 'rtmp://127.0.0.1:19350/rtmp/%%STREAM_KEY%%' 34 | PUSH_URL_TWITCH = 'rtmp://live-cdg.twitch.tv/app/%%STREAM_KEY%%' 35 | PUSH_URL_INSTAGRAM = 'rtmp://127.0.0.1:19351/rtmp/%%STREAM_KEY%%' 36 | PUSH_URL_PERISCOPE = 'rtmp://%%REGION_CODE%%.pscp.tv:80/x/%%STREAM_KEY%%' 37 | PUSH_URL_MICROSOFT_STREAM = '%%RTMP_URL%% app=live/%%APP_NAME%%' 38 | PUSH_URL_MIXCLOUD = 'rtmp://rtmp.mixcloud.com/broadcast/%%STREAM_KEY%%' 39 | PUSH_URL_DLIVE = 'rtmp://stream.dlive.tv/live/%%STREAM_KEY%%' 40 | 41 | 42 | DEFAULT_TRANSCODE_CONFIG = { 43 | 'pixels': '1280x720', 44 | 'videoBitRate': '4500k', 45 | 'videoFrameRate': 60, 46 | 'keyFrames': 60, 47 | 'audioOpts': '-c:a copy', 48 | 'logFfmpeg': True if CONFIG_FFMPEG_LOG else False, 49 | 'maxMuxingQueueSize': int(CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE) 50 | if CONFIG_FFMPEG_MAX_MUXING_QUEUE_SIZE 51 | else None, 52 | } 53 | 54 | DEFAULT_AUDIO_OPTS = { 55 | 'audioBitRate': '160k', 56 | 'audioSampleRate': '48000', 57 | } 58 | 59 | 60 | def generatePlatormPushURL(block_config): 61 | if 'platform' not in block_config: 62 | print('ERROR - Application block is missing platform element.', file=sys.stderr) 63 | exit(1) 64 | push_url = 'push-it-real-good' 65 | 66 | if block_config['platform'] == 'restream': 67 | push_url = PUSH_URL_RESTREAM.replace('%%STREAM_KEY%%', block_config['streamKey']) 68 | elif block_config['platform'] == 'youtube': 69 | push_url = PUSH_URL_YOUTUBE.replace('%%STREAM_KEY%%', block_config['streamKey']) 70 | elif block_config['platform'] == 'facebook': 71 | # must push through stunnel. Push through Facebook stunnel port. 72 | push_url = PUSH_URL_FACEBOOK.replace( 73 | '%%STREAM_KEY%%', block_config['streamKey'] 74 | ) 75 | elif block_config['platform'] == 'twitch': 76 | push_url = PUSH_URL_TWITCH.replace('%%STREAM_KEY%%', block_config['streamKey']) 77 | elif block_config['platform'] == 'instagram': 78 | # must push through stunnel. Push through Instagram stunnel port. 79 | push_url = PUSH_URL_INSTAGRAM.replace( 80 | '%%STREAM_KEY%%', block_config['streamKey'] 81 | ) 82 | elif block_config['platform'] == 'periscope': 83 | region_code = ( 84 | block_config['regionCode'] if 'regionCode' in block_config else 'ca' 85 | ) 86 | push_url = PUSH_URL_PERISCOPE.replace( 87 | '%%STREAM_KEY%%', block_config['streamKey'] 88 | ).replace('%%REGION_CODE%%', region_code) 89 | elif block_config['platform'] == 'custom': 90 | push_url = block_config['customRTMPURL'] 91 | elif block_config['platform'] == 'microsoft-stream': 92 | ms_source_url = block_config['fullRTMPURL'] 93 | ms_rtmp_url = re.search(r'^(.*)/live/', ms_source_url).group(1) 94 | ms_app_name = re.search(r'/live/(.*)$', ms_source_url).group(1) 95 | push_url = PUSH_URL_MICROSOFT_STREAM.replace( 96 | '%%RTMP_URL%%', ms_rtmp_url 97 | ).replace('%%APP_NAME%%', ms_app_name) 98 | elif block_config['platform'] == 'mixcloud': 99 | push_url = PUSH_URL_MIXCLOUD.replace( 100 | '%%STREAM_KEY%%', block_config['streamKey'] 101 | ) 102 | elif block_config['platform'] == 'dlive': 103 | push_url = PUSH_URL_DLIVE.replace('%%STREAM_KEY%%', block_config['streamKey']) 104 | else: 105 | print( 106 | 'ERROR - an unsupported platform type was provided in destination configation', 107 | file=sys.stderr, 108 | ) 109 | exit(1) 110 | return push_url 111 | 112 | 113 | def generateTranscodeConfig(transcode_config_name, block_config, config): 114 | block_config_name = block_config['name'] 115 | default_transcode_config = DEFAULT_TRANSCODE_CONFIG.copy() 116 | transcode_config_block = config.get('transcodeProfiles', {}).get( 117 | transcode_config_name, block_config.get('transcode') 118 | ) 119 | if not transcode_config_block: 120 | print( 121 | f'ERROR - unable to resolve transcode profile for {transcode_config_name} in block {block_config_name}', 122 | file=sys.stderr, 123 | ) 124 | exit(1) 125 | transcode_config = { 126 | key: copy.deepcopy(transcode_config_block.get(key, DEFAULT_TRANSCODE_CONFIG[key])) 127 | for key in default_transcode_config.keys() 128 | } 129 | transcode_config['applicationEndpoints'] = set() 130 | 131 | if 'videoKeyFrameSecs' in transcode_config_block: 132 | transcode_config['keyFrames'] = 30 * transcode_config_block['videoKeyFrameSecs'] 133 | 134 | if ('audioBitRate' in transcode_config_block) or ( 135 | 'audioSampleRate' in transcode_config_block 136 | ): 137 | transcode_config['audioOpts'] = RTMP_TRANSCODE_AUDIO_OPTS_CUSTOM.replace( 138 | '%%AUDIO_BIT_RATE%%', 139 | str(transcode_config_block.get( 140 | 'audioBitRate', DEFAULT_AUDIO_OPTS['audioBitRate'] 141 | )), 142 | ).replace( 143 | '%%AUDIO_SAMPLE_RATE%%', 144 | str(transcode_config_block.get( 145 | 'audioSampleRate', DEFAULT_AUDIO_OPTS['audioSampleRate'] 146 | )), 147 | ) 148 | return transcode_config 149 | 150 | 151 | def loadJsonConfig(path): 152 | try: 153 | with open(path, 'r') as f: 154 | config = json.load(f) 155 | except json.decoder.JSONDecodeError as err: 156 | print( 157 | "ERROR decoding JSON config file '{0}': {1}".format(path, err), 158 | file=sys.stderr, 159 | ) 160 | exit(1) 161 | except: 162 | print("ERROR loading JSON config file '{0}'".format(path), file=sys.stderr) 163 | exit(1) 164 | 165 | return config 166 | 167 | 168 | def generateConfig(config_file, nginx_config_template): 169 | config = loadJsonConfig(config_file) 170 | # unfortunate hack to make code compatible with previous spelling error 171 | config_list_key = ( 172 | 'rebroacastList' if 'rebroacastList' in config else 'rebroadcastList' 173 | ) 174 | 175 | record_mode = 'off' if CONFIG_DISABLE_RECORD else 'all' 176 | nginx_error_log = True if CONFIG_NGINX_DEBUG else False 177 | 178 | endpoint_name = config['endpoint'] if 'endpoint' in config else 'live' 179 | 180 | application_configs = {} 181 | transcode_configs = {} 182 | push_only_applications = set() 183 | 184 | for block_config in config[config_list_key]: 185 | if block_config.get('disabled', False): 186 | continue 187 | 188 | block_config_name = block_config['name'] 189 | application_configs[block_config_name] = { 190 | 'pushUrl': generatePlatormPushURL(block_config) 191 | } 192 | 193 | if ('transcodeProfile' in block_config) or 'transcode' in block_config: 194 | transcode_config_name = block_config.get( 195 | 'transcodeProfile', f'inline_{block_config_name}' 196 | ) 197 | 198 | if transcode_config_name not in transcode_configs: 199 | transcode_configs[transcode_config_name] = generateTranscodeConfig( 200 | transcode_config_name, block_config, config 201 | ) 202 | transcode_configs[transcode_config_name]['applicationEndpoints'].add( 203 | block_config_name 204 | ) 205 | 206 | else: 207 | push_only_applications.add(block_config_name) 208 | 209 | with open(nginx_config_template) as fh: 210 | template = jinja2.Template(fh.read()) 211 | 212 | return template.render( 213 | nginx_error_log=nginx_error_log, 214 | endpoint_name=endpoint_name, 215 | record_mode=record_mode, 216 | transcode_configs=transcode_configs, 217 | push_only_applications=push_only_applications, 218 | application_configs=application_configs, 219 | ) 220 | 221 | 222 | if __name__ == '__main__': 223 | if len(sys.argv) != 3: 224 | print( 225 | 'Must pass two arguments of the JSON configuration file path and the nginx config.', 226 | file=sys.stderr, 227 | ) 228 | sys.exit(1) 229 | rtmp_conf = generateConfig(sys.argv[1], sys.argv[2]) 230 | print(rtmp_conf) 231 | -------------------------------------------------------------------------------- /multistreaming-server/stunnel-conf/etc-default-stunnel: -------------------------------------------------------------------------------- 1 | # /etc/default/stunnel 2 | # Julien LEMOINE 3 | # September 2003 4 | 5 | # Change to one to enable stunnel automatic startup 6 | ENABLED=1 7 | FILES="/etc/stunnel/*.conf" 8 | OPTIONS="" 9 | 10 | # Change to one to enable ppp restart scripts 11 | PPP_RESTART=0 12 | 13 | # Change to enable the setting of limits on the stunnel instances 14 | # For example, to set a large limit on file descriptors (to enable 15 | # more simultaneous client connections), set RLIMITS="-n 4096" 16 | # More than one resource limit may be modified at the same time, 17 | # e.g. RLIMITS="-n 4096 -d unlimited" 18 | RLIMITS="" 19 | -------------------------------------------------------------------------------- /multistreaming-server/stunnel-conf/etc-stunnel-conf.d-fb.conf: -------------------------------------------------------------------------------- 1 | [fb-live] 2 | client = yes 3 | accept = 127.0.0.1:19350 4 | connect = live-api-s.facebook.com:443 5 | verifyChain = no 6 | -------------------------------------------------------------------------------- /multistreaming-server/stunnel-conf/etc-stunnel-conf.d-ig.conf: -------------------------------------------------------------------------------- 1 | [ig-live] 2 | client = yes 3 | accept = 127.0.0.1:19351 4 | connect = live-upload.instagram.com:443 5 | verifyChain = no 6 | -------------------------------------------------------------------------------- /multistreaming-server/stunnel-conf/etc-stunnel-stunnel.conf: -------------------------------------------------------------------------------- 1 | foreground = yes 2 | setuid = stunnel 3 | setgid = stunnel 4 | pid= /tmp/stunnel.pid 5 | output = /tmp/stunnel.log 6 | include = /etc/stunnel/conf.d -------------------------------------------------------------------------------- /multistreaming-server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | user=root 4 | 5 | [supervisorctl] 6 | 7 | [program:stunnel] 8 | command=/usr/bin/stunnel 9 | stdout_logfile=/dev/stdout 10 | stdout_logfile_maxbytes=0 11 | stderr_logfile=/dev/stderr 12 | stderr_logfile_maxbytes=0 13 | autorestart=true 14 | 15 | 16 | [program:stunnel-logs] 17 | command=tail -f /tmp/stunnel.log 18 | stdout_logfile=/dev/stdout 19 | stdout_logfile_maxbytes=0 20 | stderr_logfile=/dev/stderr 21 | stderr_logfile_maxbytes=0 22 | autorestart=true 23 | 24 | 25 | [program:nginx] 26 | command=sh /launch-nginx-server.sh 27 | stdout_logfile=/dev/stdout 28 | stdout_logfile_maxbytes=0 29 | stderr_logfile=/dev/stderr 30 | stderr_logfile_maxbytes=0 31 | autorestart=true 32 | --------------------------------------------------------------------------------