├── .gitignore ├── .version ├── CHANGELOG ├── README.md ├── bin ├── rstream └── rstream-transcoder └── include ├── core ├── rstream-config-crtmpd-helper ├── rstream-config-ffmpeg-helper ├── rstream-config-helper ├── rstream-config-hls-helper ├── rstream-config-nginx-helper └── rstream-core ├── freebsd9 ├── rstream-freebsd9_common-helper ├── rstream-freebsd9_crtmpd-helper ├── rstream-freebsd9_daemontools-helper ├── rstream-freebsd9_ffmpeg-helper └── rstream-freebsd9_nginx-helper └── templates ├── crtmpd-conf-flvplayback.tpl ├── crtmpd-conf-proxypublish.tpl ├── crtmpd-run-log.tpl ├── crtmpd-run.tpl ├── crtmpd-trunk-779-transparentStream.patch ├── crtmpd-users.tpl ├── ffmpeg-run-log.tpl ├── ffmpeg-run.tpl ├── libavformat-segment-c_segment-list-EXTM3U.patch ├── nginx-conf.tpl ├── nginx-rtmp-mime-types.tpl ├── nginx-rtmp-stat.xsl ├── nginx-run-log.tpl ├── nginx-run.tpl ├── rstream-conf-crtmpd.tpl ├── rstream-conf-ffmpeg.tpl ├── rstream-conf-nginx-hls.tpl ├── rstream-conf-nginx.tpl ├── rstream-firewall.dist └── stat.xsl /.gitignore: -------------------------------------------------------------------------------- 1 | shared 2 | etc 3 | src 4 | local 5 | tmp 6 | var 7 | -------------------------------------------------------------------------------- /.version: -------------------------------------------------------------------------------- 1 | TAG=0.6 2 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | TAG 0.1 2 | --- 3 | 4 | * initial release, Freebsd9 only 5 | * added "-proxy" 6 | * added "-debug-reset" 7 | 8 | TAG 0.2 9 | --- 10 | 11 | * updated to new modulable script structure 12 | * added per OS-Type helpers 13 | * created rstream-core containing cross-OS logic 14 | * added nginx-rtmpd-hls.conf-dist 15 | * updated nginx-rtmpd.conf-dist 16 | * removed "-proxy" 17 | * added "-setup crtmpd-proxy-to-nginx" 18 | * added "-nginx (start|stop|status|setup)" 19 | * added "-crtmpd (start|stop|status|setup)" 20 | 21 | TAG 0.3 22 | --- 23 | 24 | * added global "start|stop|restart" switches 25 | * added rstream-firewall.dist 0.1 - Firewalls ONE or SEVERAL IPs on a SINGLE ETHERNET ADAPTER *BSD System ! 26 | * enabled auth for broadcasters connecting to rtmp://:/proxy default 27 | * added auth default credentials in $HOME/etc/crtmpd-users.lua (username: "broadcast", password: "n3rox") 28 | * added prerequisists to transcoding 29 | 30 | TAG 0.3t 31 | --- 32 | * enhancements and fixes for transcoding compatibility 33 | * added ffmpeg source presets in $HOME/etc/ffmpeg 34 | * added rstream-transcoder -run 35 | * highly experimental ffmpeg-transcoding using: 36 | * "~rstream/bin/rstream-transcoder -run m1" == CRTMPD (RTMP / FLV) > ffmpeg > CRTMPD (tcvp / FLV) 37 | * "~rstream/bin/rstream-transcoder -run m2" == CRTMPD (RTMP / FLV) > ffmpeg > NGINX (rtmp / FLV) 38 | * added "-debug-cycle", cleans, reinstalls, configures and restarts rstream 39 | 40 | TAG 0.4 41 | --- 42 | * not released, lots of tests and trials, major code refactoring 43 | 44 | TAG 0.5 45 | --- 46 | * added rstream-config-helper, invoke it on first run 47 | * added nginx startup & control via daemontools 48 | * added crtmpd new config files 49 | * added crtmpd transparentStream support in proxypublish 50 | * added nginx new config files 51 | * added massive directory re-structuring 52 | * removed rstream-transcoder (for now) 53 | 54 | TAG 0.6 55 | --- 56 | * added new rstream-transcoder (!) 57 | * ffmpeg will now produce 8x streams via nginx-rtmp (4x for RTMP via rstream-transcoder, 4x for HLS via nginx-rtmp) 58 | * transcoding now triggered via nginx-rtmp's "exec" function 59 | * nginx-rtmp can now accept direct Wirecast connections (thank you arut!) 60 | * please read HLS and TRANSCODING notes 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RStream 0.6 2 | =========== 3 | 4 | *thin as air* Streaming CDN toolkit 5 | 6 | Content 7 | ====== 8 | * Preamble 9 | * [What can it do](https://github.com/kelexel/rstream#what-can-it-do) 10 | * [What it is](https://github.com/kelexel/rstream#what-it-is) 11 | * [What it is NOT](https://github.com/kelexel/rstream#what-it-is-not) 12 | * [Why crmptd + nginx-rtmp at the same time ?!](https://github.com/kelexel/rstream#why-crmptd--nginx-rtmp-at-the-same-time-) 13 | * [Notes on crtmpd](https://github.com/kelexel/rstream#Notes-on-crtmpd) 14 | * [Notes on nginx-rtmp](https://github.com/kelexel/rstream#Notes-on-nginx-rtmp) 15 | * [Notes on HLS](https://github.com/kelexel/rstream#notes-on-hls) 16 | * [Notes on Transcoding](https://github.com/kelexel/rstream#notes-on-transcoding) 17 | * Changelog 18 | See CHANGELOG 19 | * [Todo](https://github.com/kelexel/rstream#todo) 20 | * Requirements 21 | * [Server side requirements](https://github.com/kelexel/rstream#server-side-requirements) 22 | * [Broadcaster side requirements](https://github.com/kelexel/rstream#broadcaster-side-requirements) 23 | * [Client side requirements](https://github.com/kelexel/rstream#client-side-requirements) 24 | * [Disclaimer](https://github.com/kelexel/rstream#displaimer) 25 | * Howtos 26 | * [Howto: Per daemon control](https://github.com/kelexel/rstream#howto-per-daemon-control) 27 | * [Howto: Ssrver-side tests](https://github.com/kelexel/rstream#howto-server-side-tests) 28 | * [Howto: Client-side tests](https://github.com/kelexel/rstream#howto-client-side-tests) 29 | * [Howto: Client-side HLS tests on iOS](https://github.com/kelexel/rstream#howto-client-side-hls-tests-on-ios) 30 | * [Howto: Transcoding](https://github.com/kelexel/rstream#howto-transcoding) 31 | * [Howto: Using Wirecast as a broadcaster](https://github.com/kelexel/rstream#howto-using-wirecast-as-a-broadcaster) 32 | * [Credits](https://github.com/kelexel/rstream#credits) 33 | * [Final notes](https://github.com/kelexel/rstream#final-notes) 34 | 35 | Preamble 36 | ====== 37 | 38 | What can it do 39 | --- 40 | 41 | Setup a fully featured Streaming CDN with HTTPLiveStream + RTMP + Transcoding based on [crtmpdserver](http://www.rtmpd.com/), [nginx-rtmp](https://github.com/arut/nginx-rtmp-module), and [ffmpeg](https://github.com/FFmpeg/FFmpeg): 42 | 43 | * Let you configure already installed crtmpd, ffmpeg, or BOTH (for proxy mode !) 44 | * Sandboxes all components (temporary files, HLS streams, config files, log files ...) 45 | * Create nginx-rtmp config files 46 | * Create crtmpd conf files 47 | * Generates necessary daemontools scripts for crtmpd(/log) nginx(/log) and ffmpeg(/log) 48 | * Provide in depth control of each daemontools scripts via the *~rstream* helper 49 | * Make requirements checks (for HLS and FFMPEG notably) 50 | * Provide a wrapper to ffmpeg via *rstream-transcoder* to generate multiple bitrate (240p, 340p, 480p, 720p) streams from one single RTMP feed 51 | * Provide HLS (HTTP Live Streaming) via ffmpeg and nginx-rtmp (Read HLS notes !) 52 | * (new) Supports multiple transcoding methods (nginx-to-nginx, crtmpd-to-crtmpd) to provide multiple bitrate (240p, 340p, 480p, 720p) streams from one single RTMP feed 53 | * (new) Built-in configuration wizard 54 | * (new) Multi bitrate HLS streams (via nginx-rtmp & ffmpeg) 55 | * (experimental) HLS via *ffmpeg onnly*, can connect to either crtmpd or nginx (*~rstream-transcoder -run hls stream_name*) 56 | * Support the following broadcasters: 57 | * [Telestream Wirecast](http://www.adobe.com/products/flash-media-encoder.html) (OSX 10.7.x / Windows 7, h264/aac) 58 | * [Adobe FlashMediaLiveEncoer](http://www.adobe.com/products/flash-media-encoder.html) (OSX 10.7.x / Windows 7 / Linux, h264/aac) 59 | * http://www.osmf.org/configurator/fmp/ (Flash Player 11+, h264/aac) 60 | * [Android: OS Broadcaster](https://play.google.com/store/search?q=+OS+Broadcaster&c=apps) (Android 3+, h264/aac) 61 | * Support the following clients: 62 | * jwplayer 63 | * flowplayer 64 | * Mobile Safari: iOS/ipad 5+, iOS/iphone 5+, should work with iOS/ipad 5+ (only is HLS is enabled) 65 | * http://dl.dropbox.com/u/2918563/flvplayback.swf (Flash Player 10+) 66 | * http://www.osmf.org/configurator/fmp/ (Flash Player 10+) 67 | 68 | What it is 69 | --- 70 | 71 | * For me, a week (update: two week now) of random r&d including a heavy dose of trial an error, docs ingesting, google resarch, all possible because of [these people](https://github.com/kelexel/rstream#credits). It is meant for educational purpose only. It will only setup what you tell it too. 72 | * It uses good old Bourne shell - so it just works *out of the box* on *any* *NIX 73 | * A set of configuration files and script to simplify deploy a full-feature streaming server CDN capable of transcoding a single FLV (h264/acc no vpx/mp3) received *via* the RTMP protocol, to multiple bitrate video streams compatible with both Adobe FLASH (RTMP) and iOS-style HTTPLiveStreaming (HLS) compatible devices. 74 | * The "transcoder" is nothing less than a bourne script invoking ffmpeg with my set of settings, you are encouraged to experiment with these settings (specially the HLS ones) 75 | * Transcoder has now 3x different ways of working (check Transcoding section), each mode being able to generate 720p, 480p, 340p, 240p FLV (h264/aac) streams from a single given h264/aac stream. 76 | * IF HLS is enabled via nginx, the same broadcaster's stream will be converted to the above four streams + their equivalent in HLS streams, for a total of 8 different streams (4x RTMP and 4x HLS) 77 | * It can now work with crtmpd only, nginx only, or both crtmpd and nginx 78 | * It is per OS customizable - you can easily port rstream to *any* os, assuming you create your own ~/rstream/include/system-os/* files 79 | * It is now multiple-broadcasters-friendly ! (that was a silly limitation in pre 0.5) 80 | * It is now multi-concurent-streams-per-single-broadcaster-friendly ! (assuming you patch crtmpd with the [crtmpd-r779-transparentStream.patch](http://pastebin.com/EmNs2U9M) I wrote) 81 | 82 | What it is NOT 83 | --- 84 | 85 | * It is not a program, nor an application. It is a set of simple shell scripts that will let you deploy a generic config for a full featured RTMP > H264/HLS CDN. 86 | * It is not pefect, 0.1 was written in roughly 6hours, 0.2 was released few (sleepless) hours later, and I'm now preparing to push to 0.5 with *major* code refactoring. You should really only use this if you know what you are doing, and mostly, if you are doing on a vanilla server (i.e.: without prior specific config/files/data on it) 87 | * It is NOT-YET production-stress-tested 88 | * It is NOT-YET Linux-friendly (just fork it!) 89 | * It is NOT-YET OSX-friendly (just fork it!) 90 | * It is NOT-YET capable of steaming vpX/mp3 91 | * Is is NOT(-YET?) capable of installing nginx(-rtmp), crtmpd, or ffmpeg for you, you must do this by yourself ! 92 | 93 | Why crmptd + nginx-rtmp at the same time ?! 94 | --- 95 | 96 | The ultimate goal of this is project is to provide an *easy* way for a single Wirecast broadcaster to send one stream to *any* kind of device supporting either the RTMP or HLS protocols. 97 | 98 | At the time I'm writing these lines, two great projects exist in the Open-Source RTMP ecosystem (there are many *other* great RTMP servers out there!), crtmpdserver](http://www.rtmpd.com/), and [nginx-rtmp](https://github.com/arut/nginx-rtmp-module). 99 | 100 | Each has it's own pros and cons, see notes bellow 101 | 102 | 103 | Notes on crtmpd 104 | --- 105 | 106 | It clearly appeared to me that it was a huge competitor in the world of RTMP and video broadcasting in general, specially with it's [evostream*](http://www.evostream.com) flag-ship big brother 107 | 108 | It's main strength is the library on top of which are built every crtmpd "apps"; think of crtmpd as an advanced framework for manipulating media streams. 109 | 110 | The frustrating part, is that if, as me, you have limited knowledge of C/C++/C#, creating your own app is probably out of the equation. 111 | 112 | Luckily for me, they provide the sources of several *sample apps*, that even led me to produce [a piggy-style-patch for the proxypublish app]((http://pastebin.com/EmNs2U9M) allowing it to transparently relay any stream_name pushed by a broadcaster to a pre-given remoteServer. 113 | 114 | The fact that they provide their *framework* for free is in my humble opinion fantastic, even if it lack some very useful features out of the box (HLS / exec for transcoding...), which can be easily implemented by the programming wise. 115 | 116 | Is is worth mentioning that as of now (16/08/2012), crtmpd supports encryption over RTMPS, mostly "Adobe style" broadcaster authentication for the RTMP(S) protocols 117 | 118 | 119 | Notes on nginx-rtmp 120 | --- 121 | 122 | The first thing that struck me was *nginx* in the name. Anyone who ever dealt with high-availability-heavy-load-httpd setups knows nginx. 123 | Second, the fact that it supported HLS and "exec" was enough to convince me that [nginx-rtmp](https://github.com/arut/nginx-rtmp-module/) was going to become a key element in this project. 124 | 125 | It has a built-in trigger mechanism using http requests via customizable URLs to handle play read/record client access 126 | It has a stats module that provides a descent efficient overview of your server's current usage 127 | 128 | HLS is still considered experimental 129 | 130 | nginx-rtmp is single threaded, meaning if using exec, it is strongly advised to fork your ffmpeg scripts in the background 131 | It only supports the RTMP protocol 132 | 133 | Is is worth mentioning that as of now (16/08/2012), nginx-rtmp only supports the RTMP protocol, and has no built-in "Adobe style" broadcast user authentication mechanism 134 | 135 | If using rstream in "nginx-rtmp only" mode, you will only be able to restrain broadcaster access via allow/deny rules on per IP basis, see ~rstream/etc/nginx-rtmp.conf, or nginx-rtmp docs fo examples 136 | But I am sure this will be fixed in a few ;) 137 | 138 | Notes on HLS 139 | --- 140 | 141 | * HLS built-in generation **is not yet** implemented in the (free) crtmpd 142 | * HLS built-in generation **is** implemented in the (free) nginx-rtmp (via ffmpeg) 143 | * HLS is theoretically doable for crtmpd using ffmpeg in a standalone process (i.e.: via rstream-transcoder -run hls ) 144 | * HLS is available in nginx-rtmp via ffmpeg, no nginx-rtmp or no ffmpeg = no HLS for you 145 | * HLS support requires a recent ffmpeg (!) with RTMP support enabled, and a recent (!) version of nginx-rtmp (don't forget to add HLS support, see nginx-rtmp install notes) 146 | * HLS multi-bitrate is only available if both nginx-rtmp and ffmpeg are enabled 147 | * HLS does not -yet- work with ffmpeg directly (aka without nginx-rtmp), because I have found no way to generate an HLS friendly -segment_list (see [this ffmpeg enhancement request](https://ffmpeg.org/trac/ffmpeg/ticket/1642)) 148 | * HLS can be i/o consumming based on the concurent number of streams being HLS transcoded. Setting up a ramdisk/tmpfs in ~rstream/etc is a *great* idea, since this is where all mpeg2ts segments will be created by ffmpeg's libs via nginx-tmp 149 | 150 | Notes on Transcoding 151 | --- 152 | 153 | * ffmpeg is required for transcoding, and by this, I mean you probably will need to compile it from a freshly cloned [Ffmpeg github repo](https://github.com/FFmpeg/FFmpeg) 154 | * Since nginx-rtmp now supports "exec" on FreeBSD, it is now nginx-rtmp that invokes rstream-transcoder when a new broadcaster publishes a stream. There is no more need to have ffmpeg processes on a per streamname basis, as I was doing before with daemontools. 155 | * I have focused all my efforts right now on transcoding with nginx, but haven't forgotten crtmpd, and I am still working on a good crtmpd way to share the streams (probably pushing them via tcp ) 156 | 157 | 158 | Todo 159 | ====== 160 | 161 | * Make crtmpd transcoding 162 | * Make experimentations with webm/mp4 segments 163 | * Make rstream Linux friendly ? (you just fork it!) 164 | * Make rstream in .py or .rb ? (you just fork it!) 165 | 166 | Requirements 167 | ====== 168 | 169 | Server side requirements 170 | --- 171 | 172 | * FreeBSD 9.x - I am currently running this setup inside a FreeBSD 9.1-prelease jail, and it runs great! 173 | * nginx (compiled from a recent port tree, with the "nginx-rtmp" module enabled) 174 | * nginx-rtmp HLS (optional - needs modification of the port's Makefile) 175 | * crtmpd binary distribution, or a custom compiled binary (i.e.: with + r779-transparentStream.patch) 176 | * ffmpeg (optional - if you want transcoding to lower bitrates) 177 | * backup (if any) your previously existing nginx config files located under /usr/local/etc/nginx/* (!!!) 178 | 179 | Broadcaster side requirements 180 | --- 181 | 182 | * The RTMP broadcasting tool of your choice (Wirecast, Flash Media Live Encoder, an flv based RTMP encoder...) 183 | 184 | Client side requirements 185 | --- 186 | 187 | * An RTMP or HLS friendly client 188 | * An RTMP compatible Flash video player of sort 189 | 190 | Disclaimer 191 | ========== 192 | 193 | I am not affiliated to either crtmpd or nginx-rtmp, nor am I trying to prove one being superior to the other. 194 | I just have a *need* which requires me to use them in a *secific* way 195 | 196 | If you have an existing nginx installation please backup your WHOLE NGINX configuration BEFORE running rstream ! 197 | More precisely the following files: 198 | 199 | * /usr/local/etc/nginx/nginx.conf 200 | * /usr/local/etc/nginx/mime.types (if used in your actual setup) 201 | 202 | By using this software you agree to the possibility of breaking something or loosing all your data. 203 | 204 | You understand that *rstream-transcode* is higly experimental and that pipe'ing it's output to a log file might be a VERY BAD IDEA. 205 | 206 | Installation 207 | ====== 208 | 209 | By default rstream expects to be installed in /home/rstream 210 | 211 | Get the rstream- sources from https://github.com/kelexel/rstream 212 | 213 | ```bash 214 | # Proceed as follows using git: 215 | mkdir /home/rstream 216 | cd /home/rstream && git clone https://github.com/kelexel/rstream.git 217 | 218 | # Or downloading the current tag 219 | mkdir /home/rstream 220 | cd /home/rstream 221 | # fetch a current TAG tarball, ie: fetch -o rstream-.tgz https://github.com/kelexel/rstream/tarball/ 222 | fetch -o rstream-0.2.tgz https://github.com/kelexel/rstream/tarball/0.2 223 | ``` 224 | (In case you want to install rstream in another location, you only need to edit the HOME variable setting on top of ~rstream/bin/rstream 225 | 226 | NOTE: rstream uses *which* to find out if crtmpd/nginx/ffmpeg are installed on your system, and will exit if not found. 227 | In case you want to specify your own location for these binaries, simply edit the top lines in ~/bin/rstream: 228 | ```bash 229 | #NGINX_BIN=`which nginx` 230 | NGINX_BIN=/usr/local/sbin/nginx 231 | #CRTMPD_BIN=`which crtmpserver` 232 | CRTMPD_BIN=/my/custom/crtmpserver 233 | #FFMPEG_BIN=`which ffmpeg` 234 | FFMPEG_BIN=/usr/local/sbin/nginx 235 | ``` 236 | 237 | Start rstream one time to generate a new rstream configuration file 238 | ```bash 239 | ~rstream/bin/rstream 240 | ``` 241 | Answer the questions.. 242 | If all goes well, rstream will issue a *~rstream/bin/rstream -setup* and generate the appropriate configuration files itself 243 | 244 | 245 | Howto: Per-daemon control 246 | ====== 247 | 248 | Each daemons (crtmpd, nginx, daemontools) can be controlled via rstream 249 | 250 | ```bash 251 | # Some shortcut commands.. 252 | ~rstream/bin/rstream -crtmpd status | stop | start | restart) 253 | ~rstream/bin/rstream -nginx (status | stop | start | restart) 254 | ~daemontools/bin/rstream -daemontools (status | stop | start | restart) 255 | # control all daemons at once 256 | ~daemontools/bin/rstream stop | start | restart 257 | 258 | ## debug only - WARNING - will start from scratch, deleting all previously created files/dirs/configs ! 259 | 260 | # deletes all created dir & file structure under ~rstream/ .. take it as a "reset to factory defaults" 261 | ~daemontools/bin/rstream -debug-reset 262 | # complete a full cleanup / compile / install cycle ! warning, your configuration files will be re-written ! 263 | ~daemontools/bin/rstream -debug-cycle 264 | ``` 265 | 266 | 267 | Howto: Server-side tests 268 | ---- 269 | 270 | At this point, everything is setup and configured, but no daemons are running. 271 | Here is how to control that everything works as intended to, by starting each daemon one at a time 272 | 273 | ```bash 274 | # Start nginx 275 | ~rstream -nginx test 276 | # Start daemontools 277 | ~rstream -daemontools test 278 | # Start crtmpd/run manually at least once using: 279 | ~rstream -crtmpd test 280 | 281 | # !!! Once you are sure that everything works correctly, you can now link all daemontools-type services to your OS's daemontools service path by using: 282 | ~rstream/bin/rstream -link 283 | 284 | # finally restart the whole setup 285 | ~rstream/bin/rstream start 286 | ``` 287 | 288 | Howto: Client-side tests 289 | --- 290 | 291 | I can only recommand the "flvplayer.swf" mentioned [here](https://groups.google.com/forum/?fromgroups#!topic/c-rtmp-server/yPkD3PKnpMM[1-25]) and available for download [here](http://dl.dropbox.com/u/2918563/flvplayback.swf) 292 | 293 | * Just download the file and open it with Flash Player or a Flash Player enabled browser 294 | * Use rtmp://NGINX_RTMP_IP:NGINX_RTMP_PORT/proxy as "Connecting String" field 295 | * Hit the "Connect" button 296 | * Wait a few seconds (2-3s) 297 | * In the (un-labelled) input field just above the "Connect" button, enter your NGINX_RTMP_STREAM name 298 | * Press the Play button 299 | 300 | You should be able to see your stream. 301 | 302 | Howto: client-side HLS tests on iOS 303 | --- 304 | 305 | * Open this URL in Mobile Safari : http:///hls/.m3u8 306 | 307 | Howto: Transcoding 308 | ====== 309 | 310 | Transcoding for nginx 311 | --- 312 | 313 | Transcoding in nginx-rtmp is now controlled via nginx-rtmp itself (prior version needed a separate script). nginx-rtmp uses "exec" function to start ~rstream/bin/rstream-transcoder, a glorified wrapper-to-ffmpeg. You are encouraged to modify any settings in it that you will see fit. 314 | Any stream pushed to the app "proxy" will be transcoded as HLS and H264 streams automagically to the following URLs: 315 | 316 | ```bash 317 | # rtmp://NGINX_RTMP_IP:NGINX_RTMP_PORT/r/NGINX_RTMP_STREAM_720p 318 | # rtmp://NGINX_RTMP_IP:NGINX_RTMP_PORT/r/NGINX_RTMP_STREAM_480p 319 | # rtmp://NGINX_RTMP_IP:NGINX_RTMP_PORT/r/NGINX_RTMP_STREAM_360p 320 | # rtmp://NGINX_RTMP_IP:NGINX_RTMP_PORT/r/NGINX_RTMP_STREAM_240p 321 | ``` 322 | 323 | 324 | Howto: Using Wirecast as a broadcaster 325 | ---- 326 | 327 | Download and install Wirecast(pro) demo from http://www.telestream.net/wirecast/overview.htm 328 | 329 | Go to Broadcast settings (on OSX, CMD+Y) 330 | Create a new broadcast profile profile containing: 331 | 332 | * Input the matching url (yes the /proxy is required and fixed): rtmp://:/proxy 333 | * Set authentication settings with username "broadcast", password "n3rox". The user list is located in $HOME/etc/crtmpd-users.lua 334 | * Set User Agent to FMLE/3.0 335 | * Set stream name to 336 | 337 | 338 | Credits 339 | ====== 340 | 341 | I would like to extend my *diamonds for ever* to these persons / teams: 342 | 343 | * arut, for his patience and port of nginx-rtmp (available at https://github.com/arut/nginx-rtmp-module) 344 | * the people helping and improving crtmpserver, alias crtmpd, alias c++rtmpserver (available at http://www.rtmpd.com/) 345 | * whoever created and shared http://dl.dropbox.com/u/2918563/flvplayback.swf 346 | * whoever created and shared http://www.osmf.org/configurator/fmp/ 347 | * lobotom(.org), for the Android testing 348 | * #nginx@freenode 349 | * #freebsd@freenode 350 | * #ffmpeg@freenode 351 | * #mootools@freenode 352 | * #monome@freenode 353 | 354 | Final notes 355 | ====== 356 | 357 | Take this *thing* as a training exercise. 358 | First to learn the components required in a modern full featured video CDN platform. 359 | Second, because slamming my head on the wall several times did help me understand and learn some of the key concepts behind HLS, ffmpeg, and a few other things. 360 | If it helps you learn a thing or two, than I'm happy. 361 | If their are peaces of it (I honestly think a few shell functions in this script are quite helpful) you want to reuse, please do so, but be fair. 362 | People behind projects like crtmpd or nginx-rtmp are the true hero, I am only exploiting / requesting / admiring / troubleshooting / bug-reporting / enhancement-suggesting their work. 363 | 364 | Open-Source 4 ever. 365 | -------------------------------------------------------------------------------- /bin/rstream: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | # The root directory where everything will be set 16 | HOME="/home/rstream" 17 | # User to which everything will be setuidgid to 18 | # This only checks & creates the default user test on your system 19 | USER="rstream" 20 | 21 | NGINX_BIN=`which nginx` 22 | CRTMPD_BIN=`which crtmpserver` 23 | FFMPEG_BIN=`which ffmpeg` 24 | # Set the following to 1 if you patched crtmpd with crtmpd-r779-transparentStream.patch found here http://pastebin.com/EmNs2U9M 25 | CRTMPD_TRANSPARENT_STREAM=1 26 | 27 | VERBOSE=0 28 | 29 | 30 | ######################### 31 | ######################### 32 | ######################### 33 | # You should not need to edit anything below this point. 34 | # If you have/feel the need to do otherwise, please inform me of your changes via github. 35 | ######################### 36 | ######################### 37 | ######################### 38 | 39 | . $HOME/.version 40 | 41 | # set DAEMONTOOLS_SERVICE based on default port service path 42 | DAEMONTOOLS_SERVICE="/var/service" 43 | 44 | # clear dirty terminals 45 | clear 46 | 47 | #### 48 | ### Load OS Core files 49 | #### 50 | echo "" 51 | echo "" 52 | ## 53 | if [ ! -f $HOME/include/core/rstream-core ]; then echo "!! invalid rstream setup - invalid HOME ?"; exit 99; fi 54 | . $HOME/include/core/rstream-core 55 | 56 | #### 57 | ### Load OS Core files 58 | #### 59 | case `uname -s` in 60 | FreeBSD) system_os="freebsd9";; 61 | *) echo "!! Sorry, but your current Operating System is not supported yet, exiting." exit 2;; 62 | esac 63 | echo "########## rstream $TAG for $system_os" 64 | echo "" 65 | . $HOME/include/${system_os}/rstream-${system_os}_common-helper 66 | 67 | rstream-init(){ 68 | if [ -f $HOME/etc/rstream.conf ]; then 69 | . $HOME/etc/rstream.conf 70 | . $HOME/include/${system_os}/rstream-${system_os}_crtmpd-helper 71 | . $HOME/include/${system_os}/rstream-${system_os}_daemontools-helper 72 | . $HOME/include/${system_os}/rstream-${system_os}_nginx-helper 73 | . $HOME/include/${system_os}/rstream-${system_os}_ffmpeg-helper 74 | rstream-core-init 75 | rstream-router $1 $2 76 | else 77 | . $HOME/include/core/rstream-config-helper 78 | rstream-core-init 79 | rstream-config 80 | echo "" 81 | echo "" 82 | echo "** Configuration was saved to $HOME/etc/rstream.conf" 83 | echo "*** Performing -setup" 84 | rstream-init "-setup" 85 | fi 86 | } 87 | 88 | rstream-init $1 $2 89 | 90 | # nice and clean .. 91 | echo "" 92 | echo "> done" 93 | echo "" 94 | exit 0; 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /bin/rstream-transcoder: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-transcoder 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | HOME="/home/rstream" 16 | # User to which everything will be setuidgid to 17 | # This only checks & creates the default user test on your system 18 | USER="rstream" 19 | 20 | # set DAEMONTOOLS_SERVICE based on default port service path 21 | DAEMONTOOLS_SERVICE="/var/service" 22 | 23 | VERBOSE=0 24 | 25 | HLS_CLEANUP=0 26 | 27 | ######################### 28 | ######################### 29 | ######################### 30 | # You should not need to edit anything below this point. 31 | # If you have/f[]eel the need to do otherwise, please inform me of your changes via github. 32 | ######################### 33 | ######################### 34 | ######################### 35 | 36 | . $HOME/.version 37 | 38 | #### 39 | ### Load OS Core files 40 | #### 41 | echo "" 42 | echo "" 43 | ## 44 | if [ ! -f $HOME/include/core/rstream-core ]; then echo "!! invalid rstream setup - invalid HOME ?"; exit 99; fi 45 | . $HOME/include/core/rstream-core 46 | 47 | #### 48 | ### Load OS Core files 49 | #### 50 | case `uname -s` in 51 | FreeBSD) system_os="freebsd9";; 52 | *) echo "!! Sorry, but your current Operating System is not supported yet, exiting." exit 2;; 53 | esac 54 | echo "########## rstream-transcoder-$TAG for rstream $TAG on $system_os" 55 | echo "" 56 | . $HOME/include/${system_os}/rstream-${system_os}_common-helper 57 | . $HOME/etc/rstream.conf 58 | . $HOME/include/${system_os}/rstream-${system_os}_crtmpd-helper 59 | . $HOME/include/${system_os}/rstream-${system_os}_daemontools-helper 60 | . $HOME/include/${system_os}/rstream-${system_os}_nginx-helper 61 | . $HOME/include/${system_os}/rstream-${system_os}_ffmpeg-helper 62 | rstream-core-init 63 | 64 | 65 | genStreamDestinations(){ 66 | proto=$1 67 | dest_host=$2 68 | dest_port=$3 69 | dest_app=$4 70 | stream=$5 71 | # a bit of logic .. 72 | dest_720="$proto://${dest_host}:${dest_port}/${dest_app}/${stream}_720p" 73 | dest_480="$proto://${dest_host}:${dest_port}/${dest_app}/${stream}_480p" 74 | dest_360="$proto://${dest_host}:${dest_port}/${dest_app}/${stream}_360p" 75 | dest_240="$proto://${dest_host}:${dest_port}/${dest_app}/${stream}_240p" 76 | } 77 | 78 | 79 | genPlaylistMulti() 80 | { 81 | cd $2 82 | echo "*+ generating new multi-bitrate ${1}.m3u8 playlist"; 83 | if [ ! -f ./${1}_360p.m3u8 ]; then echo "Error, ffmpeg not running ? "; 84 | echo `pwd`; 85 | exit 1; fi 86 | playlist=${1}.m3u8 87 | echo "#EXTM3U" > $playlist 88 | # echo "#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=128000" >> $playlist 89 | # echo "${1}_240p.m3u8" >> $playlist 90 | echo "#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=256000" >> $playlist 91 | echo "${1}_360p.m3u8" >> $playlist 92 | echo "#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=396000" >> $playlist 93 | echo "${1}_480p.m3u8" >> $playlist 94 | # echo "#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=512000" >> $playlist 95 | # echo "${1}_720p.m3u8" >> $playlist 96 | 97 | } 98 | 99 | transcoderNginxHLS(){ 100 | if [ -z $FFMPEG_NGINX_ENABLE ] || [ ! $FFMPEG_NGINX_ENABLE -eq 1 ]; then echo "Error: \"-run nginx \" supplied, but FFMPEG_NGINX_ENABLE is not set to \"1\" in $HOME/etc/rstream.conf, exiting !"; exit 98; fi 101 | app="proxy" 102 | if [ -z $1 ]; then echo "!! error missing stream name, exiting !!"; exit 99; fi 103 | stream=$1 104 | 105 | src="rtmp://$NGINX_RTMP_IP:$NGINX_RTMP_PORT/$app/$stream" 106 | 107 | checkDir $HOME/tmp/ffmpeg/hls -c www 777 108 | 109 | cd $HOME/tmp/ffmpeg/hls 110 | 111 | if [ ! -z $HLS_CLEANUP ] && [ $HLS_CLEANUP -eq 1 ]; then 112 | echo "** Cleaning up HLS files older than 5 minutes" 113 | find $HOME/tmp/ffmpeg/hls -mmin +5 -name "*.m3u8" -o -name "*.ts" -o -name "*.core" -exec rm -f {} \; 114 | fi 115 | 116 | # if [ -f $HOME/tmp/ffmpeg/hls/lock.${stream} ]; then echo "!! Ffmpeg already running for stream $stream ?"; exit 0; fi 117 | 118 | (sleep 20 && genPlaylistMulti $stream $HOME/tmp/ffmpeg/hls) & 119 | 120 | cmd="" 121 | cmd="$cmd -re -c:a libfaac -ar 44000 -b:a 96k -flags -global_header -map 0 -f segment -segment_time 10 -segment_format mpegts ${stream}_720p%05d.ts" 122 | # cmd="$cmd -re -c:a libfaac -ar 44000 -b:a 96k -c:v libx264 -preset ultrafast -crf 23 -s 854x480 -b:v 296k -vpre libx264-ipod640 -flags -global_header -map 0 -f segment -segment_time 10 -segment_list ${stream}_480p.m3u8 -segment_list_live 1 -segment_list_size 10 -segment_format mpegts ${stream}_480p%05d.ts" 123 | # cmd="$cmd -re -c:a libfaac -ar 22050 -b:a 64k -c:v libx264 -preset ultrafast -crf 23 -s 640x360 -b:v 256k -vpre libx264-ipod320 -flags -global_header -map 0 -f segment -segment_time 10 -segment_list ${stream}_360p.m3u8 -segment_list_live 1 -segment_list_size 10 -segment_format mpegts ${stream}_360p%05d.ts" 124 | # cmd="$cmd -re -c:a libfaac -ar 22050 -b:a 48k -c:v libx264 -preset ultrafast -crf 23 -s 426x240 -b:v 128k -vpre libx264-ipod320 -flags -global_header -map 0 -f segment -segment_time 10 -segment_list ${stream}_240p.m3u8 -segment_list_live 1 -segment_list_size 10 -segment_format mpegts ${stream}_240p%05d.ts" 125 | logHeader "Running enconding args: $cmd" 126 | $FFMPEG_BIN -loglevel info -i "$src buffer=3000 live=1 timeout=500" $cmd 127 | sleep 3 128 | } 129 | # nginx transcoding - working as of 0.4 130 | transcoderNginxH264(){ 131 | if [ ! -f $FFMPEG_BIN ]; then echo "!! error FFMPEG_BIN not found !!"; exit 99; fi 132 | if [ -z $FFMPEG_NGINX_ENABLE ] || [ ! $FFMPEG_NGINX_ENABLE -eq 1 ]; then echo "Error: \"-run nginx \" supplied, but FFMPEG_NGINX_ENABLE is not set to \"1\" in $HOME/etc/rstream.conf, exiting !"; exit 98; fi 133 | app="proxy" 134 | dest_app="r" 135 | if [ -z $1 ]; then echo "!! error missing stream name, exiting !!"; exit 99; fi 136 | stream=$1 137 | 138 | if [ -f $HOME/tmp/nginx/hls/lock.${stream} ]; then echo "Lock found for stream $stream !! exiting"; exit 0; fi 139 | touch $HOME/tmp/nginx/hls/lock.${stream} 140 | 141 | src="rtmp://$NGINX_RTMP_IP:$NGINX_RTMP_PORT/$app/$stream" 142 | genStreamDestinations "rtmp" $NGINX_RTMP_IP $NGINX_RTMP_PORT $dest_app $stream h264 143 | HLS_CLEANUP=1 144 | # if hls is enabled and set to nginx, create the multi-bitrate playlist 10 secs after the stream started to aboid "iOS stuck on black screen" 145 | if [ ! -z $HLS_ENABLE ] && [ $HLS_ENABLE -eq 1 ] && [ ! -z $HLS_TYPE ] && [ $HLS_TYPE = "nginx" ]; then 146 | checkDir $HOME/tmp/nginx/hls -c www 777; 147 | if [ ! -z $HLS_CLEANUP ] && [ $HLS_CLEANUP -eq 1 ]; then 148 | echo "** Cleaning up HLS files older than 5 minutes" 149 | find $HOME/tmp/nginx/hls -mmin +5 -name "${stream}_*.m3u8" -o -name "${stream}_*.ts" -o -name "lock.${stream}" -exec rm -f {} \; 150 | fi 151 | echo "** Launching multi-bitrate sleeping beauty" 152 | (sleep 10 && genPlaylistMulti $stream $HLS_PATH/hls) & 153 | fi 154 | cmd="" 155 | # cmd="$cmd -re -c:a libfaac -ar 44100 -b:a 96k -c:v libx264 -preset fast -crf 16 -s 1280x720 -b:v 1024k -r 25 -metadata streamName=${stream}_720p -f flv $dest_720" 156 | # cmd="$cmd -re -acodec copy -vcodec copy -metadata streamName=${stream}_720p -r 25 -f flv $dest_720" 157 | # cmd="$cmd -re -c:a libfaac -ar 44100 -b:a 96k -c:v libx264 -preset fast -crf 18 -s 854x480 -b:v 512k -r 25 -metadata streamName=${stream}_480p -f flv $dest_480" 158 | # cmd="$cmd -re -c:a libfaac -ar 22050 -b:a 64k -c:v libx264 -preset ultrafast -crf 20 -s 640x360 -b:v 396k -r 25 -metadata streamName=${stream}_360p -f flv $dest_360" 159 | # cmd="$cmd -re -c:a libfaac -ar 22050 -b:a 48k -c:v libx264 -preset ultrafast -crf 23 -s 426x240 -b:v 256k -r 25 -metadata streamName=${stream}_240p -f flv $dest_240" 160 | cmd="$cmd -re -acodec copy -vcodec copy -metadata streamName=${stream}_720p -r 25 -f flv $dest_720" 161 | cmd="$cmd -re -c:a libfaac -ar 44100 -b:a 96k -c:v libx264 -preset fast -crf 18 -s 800x600 -b:v 512k -r 25 -metadata streamName=${stream}_480p -f flv $dest_480" 162 | cmd="$cmd -re -c:a libfaac -ar 22050 -b:a 64k -c:v libx264 -preset ultrafast -crf 20 -s 600x480 -b:v 396k -r 25 -metadata streamName=${stream}_360p -f flv $dest_360" 163 | cmd="$cmd -re -c:a libfaac -ar 22050 -b:a 48k -c:v libx264 -preset ultrafast -crf 23 -s 320x240 -b:v 256k -r 25 -metadata streamName=${stream}_240p -f flv $dest_240" 164 | logHeader "Running enconding args: $cmd" 165 | $FFMPEG_BIN -loglevel fatal -i "$src buffer=100 timeout=2" $cmd 166 | rm -f $HOME/tmp/nginx/hls/lock.${stream} 167 | 168 | #exec $FFMPEG_BIN -threads 16 -i "$src live=1" $cmd 169 | } 170 | 171 | transcoderCrtmpd(){ 172 | if [ -z $FFMPEG_CRTMPD_ENABLE ] || [ ! $FFMPEG_CRTMPD_ENABLE -eq 1 ]; then echo "Error: \"-run crtmpd \" supplied, but FFMPEG_CRTMPD_ENABLE is not set to \"1\" in $HOME/etc/rstream.conf, exiting !"; exit 98; fi 173 | if [ -z $1 ]; then echo "!! error missing stream name, exiting !!"; exit 99; fi 174 | 175 | app="proxy" 176 | dest_app="r" 177 | stream=$1 178 | src="rtmp://$CRTMPD_RTMP_IP:$CRTMPD_RTMP_PORT/$app/$stream" 179 | 180 | genStreamDestinations "tcp" $CRTMPD_LIVEFLV_IP $CRTMPD_LIVEFLV_PORT $stream 181 | cmd="" 182 | cmd="$cmd -re -acodec libfaac -ar 44100 -b:a 96k -vcodec libx264 -s 1280x720 -b:v 896k -f flv -metadata streamName=${stream}_720p -f flv $dest_720" 183 | cmd="$cmd -re -acodec libfaac -ar 44100 -b:a 96k -vcodec libx264 -s 854x480 -b:v 512k -f flv -metadata streamName=${stream}_480p -f flv $dest_480" 184 | cmd="$cmd -re -acodec libfaac -ar 22050 -b:a 96k -vcodec libx264 -s 640x360 -b:v 396k -f flv -metadata streamName=${stream}_360p -f flv $dest_360" 185 | cmd="$cmd -re -acodec libfaac -ar 22050 -b:a 48k -vcodec libx264 -s 426x250 -b:v 256k -f flv -metadata streamName=${stream}_240p -f flv $dest_240" 186 | echo "" 187 | logHeader "Running $FFMPEG_BIN -threads 15 -i \"$src live=1\" $cmd" 188 | echo 189 | exec $FFMPEG_BIN -i "$src live=1" $cmd 190 | } 191 | 192 | routeTranscoder(){ 193 | 194 | if [ -z $1 ]; then routeHelp; exit 99; fi 195 | case $1 in 196 | -run) 197 | if [ -z $2 ]; then routeHelp; exit 99; fi 198 | case $2 in 199 | crtmpd) transcoderCrtmpd $3;; # CRTMPD (RTMP / FLV) > ffmpeg > CRTMPD (tcvp / FLV) 200 | nginx) transcoderNginxH264 $3;; # CRTMPD (RTMP / FLV) > ffmpeg > NGINX (rtmp / FLV) 201 | hls) transcoderNginxHLS $3;; # CRTMPD (RTMP / FLV) > ffmpeg > NGINX (rtmp / FLV) 202 | *) routeHelp;; 203 | esac 204 | ;; 205 | -service-create) ffmpeg-router "create" $3;; 206 | -service-link) ffmpeg-router "link" $3;; 207 | esac 208 | } 209 | 210 | 211 | routeTranscoder $1 $2 $3 $4 212 | 213 | #### Below lies the graveyard of my ffmpeg tests.. 214 | 215 | #checkDir $HLS_PATH/$app/$stream -rc 216 | 217 | # From https://groups.google.com/forum/#!topic/c-rtmp-server/bzsV61wJGHg[1-25] 218 | #ffmpeg -i "rtmp://localhost:1935/live/mystream live=1" -fpre "/usr/share/ffmpeg/libx264-ipod640.ffpreset" -vcodec libx264 -acodec aac -ac 2 -ar 44100 -ab 127k -strict experimental -f flv "rtmp://localhost:1935/live/mystream_recode live=1" 219 | 220 | 221 | #-re -acodec libfaac -ar 22050 -b:a 96 -vcodec libx264 -s svga -b:v 500k -f flv "rtmp://localhost:1935/live/test_500?authmod=adobe&login=broadcast&password=n3rox flashver=FMLE/3.0\20(compatible;\20FMSc/1.0)" 222 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s svga -b:v 500k -f flv "rtmp://localhost:1935/live/test_500?login=broadcast&password=n3rox flashver=FMLE/3.0\20(compatible;\20FMSc/1.0)" 223 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s svga -b:v 500k -f flv "/home/stream/docs/test_500b.flv" 224 | #ffmpeg -i "rtmp://localhost/live/test live=1" \ 225 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s svga -b:v 500k -f flv "rtmp://localhost/live/test_500" 226 | 227 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s vga -b 300k -f flv "rtmp://localhost/live/test_300" 228 | # 229 | 230 | #ffmpeg -threads 15 -i "rtmp://localhost/live/test live=1" \ 231 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s svga -b 500k -f flv "rtmp://localhost/live/test_500" \ 232 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s vga -b 300k -f flv "rtmp://localhost/live/test_300" \ 233 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s qvga -b 150k -f flv "rtmp://localhost/live/test_150" \ 234 | #-re -acodec libfaac -ar 22050 -vcodec libx264 -s qqvga -b 50k -f flv "rtmp://localhost/live/test_50" 235 | 236 | # cmd="$cmd -re -vcodec libvpx -s 1280x720 -filter:v yadif -g 120 -level 216 -profile:v 0 -qmax 42 -qmin 10 -rc_buf_aggressivity 0.95 -vb 1M -acodec libvorbis -aq 90 -ac 1 -metadata streamName=${stream}_720p_vp8 -f webm $dest_720" 237 | 238 | 239 | # -f flv "rtmp://live.justin.tv/app/$STREAM_KEY flashver=FMLE/3.0\20(compatible;\20FMSc/1.0)" 240 | 241 | #routeTranscoder $1 $2 242 | 243 | # nice and clean .. 244 | echo "" 245 | echo "> done" 246 | echo "" 247 | exit 0; 248 | -------------------------------------------------------------------------------- /include/core/rstream-config-crtmpd-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-config-crtmpd-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | if [ ! -f $CRTMPD_BIN ]; then echo "!! error, crtmpd not found, exiting !!"; exit 99; fi 17 | 18 | logSection "* entering crtmpd config helper" 19 | 20 | CRTMPD_RTMP_IP="" 21 | CRTMPD_RTMP_PORT="" 22 | CRTMPD_LIVEFLV_IP="" 23 | CRTMPD_LIVEFLV_PORT="" 24 | CRTMPD_REGEN_CONF="1" 25 | 26 | askCrtmpdBin(){ 27 | logSection "General config" 28 | echo -n "Where is your crtmpserver binary ? " 29 | read tmp 30 | if [ ! -f $tmp ]; then echo "!! cannot find crtmpserver binary in $tmp !!"; askCrtmpdBin; 31 | else CRTMPD_BIN=$tmp; fi 32 | } 33 | if [ -z $CRTMPD_BIN ]; then askCrtmpdBin; fi 34 | 35 | askRTMP(){ 36 | logSection "RTMP config" 37 | 38 | echo -n "What IP address should crtmpd use to listen to incoming and outgoing RTMP connections [$HOST_IP] ? " 39 | read CRTMPD_RTMP_IP 40 | if [ -z $CRTMPD_RTMP_IP ]; then CRTMPD_RTMP_IP=$HOST_IP; fi 41 | 42 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then port=1936; else port=1935; fi 43 | echo -n "What PORT should crtmpd use to listen to incoming and outgoing RTMP connections on $CRTMPD_RTMP_IP [$port] ? " 44 | read CRTMPD_RTMP_PORT 45 | if [ -z $CRTMPD_RTMP_PORT ]; then CRTMPD_RTMP_PORT=$port; fi 46 | 47 | echo "** Are these settings correct ?" 48 | echo "- crtmpd RTMP IP: $CRTMPD_RTMP_IP" 49 | echo "- crtmpd RTMP PORT: $CRTMPD_RTMP_PORT" 50 | echo -n "[y/N] " 51 | read tmp 52 | case $tmp in 53 | y|Y) echo "* ok";; 54 | *) askRTMP;; 55 | esac 56 | } 57 | if [ -z $CRTMPD_RTMP_IP ] || [ -z $CRTMPD_RTMP_PORT ]; then askRTMP; fi 58 | 59 | askProxyData(){ 60 | logSection "PROXY Push config" 61 | 62 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then rtmp_host="rtmp://$CRTMPD_RTMP_IP:1935/proxy" 63 | else rtmp_host="rtmp://user:pass@host:port/app"; fi 64 | echo -n "To what rtmp address should we push the current stream to (do not include the streamName in the url!) ? [$rtmp_host] " 65 | read CRTMPD_PROXY_URL 66 | if [ -z $CRTMPD_PROXY_URL ]; then CRTMPD_PROXY_URL=$rtmp_host; fi 67 | 68 | echo -n "Do you want to enable proxy transparentStream mode ? (implies you patched crtmpd with r779-transparentStream-patch !) ? [y/N] " 69 | read tmp 70 | case $tmp in 71 | y|Y) CRTMPD_PROXY_TRANSPARENT=1;; 72 | n) CRTMPD_PROXY_TRANSPARENT=0;; 73 | *) askProxyData;; 74 | esac 75 | 76 | if [ ! -z $CRTMPD_PROXY_TRANSPARENT ] && [ $CRTMPD_PROXY_TRANSPARENT -eq 1 ]; then 77 | echo "** Skipping localStreamName and targetStreamName (CRTMPD_PROXY_TRANSPARENT is set to true)" 78 | else 79 | echo -n "What local stream should we push to $CRTMPD_PROXY_URL [test] ? " 80 | read CRTMPD_PROXY_LSTREAM 81 | if [ -z $CRTMPD_PROXY_LSTREAM ]; then CRTMPD_PROXY_LSTREAM="test"; fi 82 | 83 | echo -n "As what destination stream name should we push local stream \"$CRTMPD_PROXY_LSTREAM\" to \"$CRTMPD_PROXY_URL\" [$CRTMPD_PROXY_LSTREAM] ? " 84 | read CRTMPD_PROXY_DSTREAM 85 | if [ -z $CRTMPD_PROXY_DSTREAM ]; then CRTMPD_PROXY_DSTREAM=$CRTMPD_PROXY_LSTREAM; fi 86 | fi 87 | 88 | echo "** Are these settings correct ?" 89 | echo "- crtmpd PROXY URL: $CRTMPD_PROXY_URL" 90 | if [ -z $CRTMPD_TRANSPARENT_STREAM ] || [ ! $CRTMPD_TRANSPARENT_STREAM -eq 1 ]; then 91 | echo "- crtmpd PROXY LOCAL STREAM: $CRTMPD_PROXY_LSTREAM" 92 | echo "- crtmpd PROXY DESTINATION STREAM: $CRTMPD_PROXY_TRANSPARENT" 93 | else 94 | echo "- CRTMPD_PROXY_TRANSPARENT is enabled in crtmpd !" 95 | fi 96 | echo -n "[y/N] " 97 | read tmp 98 | case $tmp in 99 | y|Y) echo "* ok";; 100 | *) askProxyData;; 101 | esac 102 | } 103 | echo -n "Do you want to enable PUSH style PROXY [y/N] ? " 104 | read tmp 105 | case $tmp in 106 | y|Y) CRTMPD_PROXY_ENABLE=1;; 107 | *) CRTMPD_PROXY_ENABLE=0;; 108 | esac 109 | 110 | if [ ! -z $CRTMPD_PROXY_ENABLE ] && [ $CRTMPD_PROXY_ENABLE -eq 1 ]; then 111 | if [ -z $CRTMPD_PROXY_URL ] || [ -z $CRTMPD_PROXY_LSTREAM ] || [ -z $CRTMPD_PROXY_DSTREAM ]; then askProxyData; fi 112 | fi 113 | 114 | askLIVEFLV(){ 115 | logSection "LIFE FLV config (required for transcoding)" 116 | echo -n "What IP address should crtmpd use to listen to incoming transcoded LIVE FLV connections [$CRTMPD_RTMP_IP] ? " 117 | read CRTMPD_LIVEFLV_IP 118 | if [ -z $CRTMPD_LIVEFLV_IP ]; then CRTMPD_LIVEFLV_IP=$CRTMPD_RTMP_IP; fi 119 | 120 | echo -n "What PORT should crtmpd use to listen to incoming transcoded LIVE FLV connections on $CRTMPD_LIVEFLV_IP [21935] ? " 121 | if [ ! -z $CRTMPD_RTMP_PORT ]; then echo -n "! Do not use $CRTMPD_RTMP_PORT ! "; fi 122 | read CRTMPD_LIVEFLV_PORT 123 | if [ -z $CRTMPD_LIVEFLV_PORT ]; then CRTMPD_LIVEFLV_PORT=21935; fi 124 | 125 | echo "** Are these settings correct ?" 126 | echo "- crtmpd LIVE-FVL IP: $CRTMPD_LIVEFLV_IP" 127 | echo "- crtmpd LIVE-FLV PORT: $CRTMPD_LIVEFLV_PORT" 128 | echo -n "[y/N] " 129 | read tmp 130 | case $tmp in 131 | y|Y) echo "* ok";; 132 | *) askLIVEFLV;; 133 | esac 134 | } 135 | #if [ ! -z $FFMPEG_CRTMPD_ENABLE ] && [ $FFMPEG_CRTMPD_ENABLE -eq 1 ]; then 136 | # if [ -z $CRTMPD_LIVEFLV_IP ] || [ -z $CRTMPD_LIVEFLV_PORT ]; then askLIVEFLV; fi 137 | #fi 138 | -------------------------------------------------------------------------------- /include/core/rstream-config-ffmpeg-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-config-ffmpeg-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | if [ ! -f $FFMPEG_BIN ]; then echo "!! error, ffmpeg not found, exiting !!"; exit 99; fi 17 | 18 | FFMPEG_TRANSCODER_IP="" 19 | FFMPEG_NGINX_ENABLE=0 20 | FFMPEG_CRTMPD_ENABLE=0 21 | 22 | logSection "* entering FFMPEG config helper" 23 | 24 | askTranscodingSupport(){ 25 | echo -n "* Do you want to enable transcoding support [y|N] ? " 26 | read tmp 27 | case $tmp in 28 | y|Y) echo "-! enabling ffmpeg"; FFMPEG_ENABLE=1;; 29 | *) echo "-! disabling ffmpeg"; FFMPEG_ENABLE=0;; 30 | esac 31 | } 32 | if [ -z $FFMPEG_ENABLE ]; then askTranscodingSupport; fi 33 | 34 | askFfmpegIp(){ 35 | logHeader "General config" 36 | if [ -z $CRTMPD_RTMP_IP ]; then tmp="x.x.x.x"; else tmp=$CRTMPD_RTMP_IP; fi 37 | echo -n "What source IP address will ffmpeg use when connecting to transcoding destinations [$tmp] ? " 38 | read FFMPEG_TRANSCODER_IP 39 | if [ -z $FFMPEG_TRANSCODER_IP ] && [ ! -z $CRTMPD_RTMP_IP ]; then FFMPEG_TRANSCODER_IP=$CRTMPD_RTMP_IP; fi 40 | if [ -z $FFMPEG_TRANSCODER_IP ] && [ -z $CRTMPD_RTMP_IP ]; then askFfmpegIp; fi 41 | } 42 | if [ ! -z $FFMPEG_ENABLE ] && [ $FFMPEG_ENABLE -eq 1 ]; then askFfmpegIp; fi 43 | 44 | askTranscoderType(){ 45 | # if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then 46 | # echo 47 | # echo -n "** crtmpd is enabled, do you want to transcode *all* streams pushed to \"rtmp://$CRTMPD_RTMP_IP:$CRTMPD_RTMP_PORT/r/\" ? [y/N] " 48 | # read tmp 49 | # case $tmp in 50 | # y|Y) echo "-! enabling ffmpeg-transcoding (240p, 360p, 480p, 720p) for crtmpd"; FFMPEG_CRTMPD_ENABLE=1;; 51 | # n) echo "-! disabling ffmpeg-transcoding for crtmpd"; FFMPEG_CRTMPD_ENABLE=0;; 52 | # *) askTranscoderType;; 53 | # esac 54 | # if [ ! -z $FFMPEG_CRTMPD_ENABLE ] && [ $FFMPEG_CRTMPD_ENABLE -eq 1 ]; then 55 | # if [ -z $CRTMPD_LIVEFLV_IP ] || [ -z $CRTMPD_LIVEFLV_PORT ]; then askLIVEFLV; fi 56 | # fi 57 | # fi 58 | 59 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then 60 | echo 61 | echo -n "** nginx is enabled, do you want to transcode *all* streams pushed to \"rtmp://$NGINX_RTMP_IP:$NGINX_RTMP_PORT/proxy/\" ? [y/N] " 62 | read tmp 63 | case $tmp in 64 | y|Y) echo "-! enabling ffmpeg-transcoding (240p, 360p, 480p, 720p) for nginx"; FFMPEG_NGINX_ENABLE=1;; 65 | *) echo "-! disabling ffmpeg-transcoding for nginx"; FFMPEG_NGINX_ENABLE=0;; 66 | esac 67 | fi 68 | } 69 | if [ ! -z $FFMPEG_ENABLE ] && [ $FFMPEG_ENABLE -eq 1 ]; then askTranscoderType; fi 70 | 71 | -------------------------------------------------------------------------------- /include/core/rstream-config-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-confg-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | RSTREAM_TYPE="" 18 | CRTMPD_ENABLE="" 19 | NGINX_ENABLE="" 20 | FFMPEG_ENABLE="" 21 | HLS_ENABLE="" 22 | 23 | #### 24 | ### Start the installer logic 25 | #### 26 | rstream-config(){ 27 | logHeader "* loading config-helper"; 28 | 29 | CONFIG_FILE=$HOME/etc/rstream.conf 30 | CRTMPD_ENABLE="" 31 | NGINX_ENABLE="" 32 | askServers(){ 33 | echo "" 34 | echo "* What type of setup do you want ?" 35 | echo "1. crtmpserver only" 36 | echo "2. nginx-rtmp only" 37 | echo "3. crtmpserver AND nginx-rtmp" 38 | echo -n "[1/2/3] " 39 | read tmp 40 | 41 | case $tmp in 42 | 1) CRTMPD_ENABLE=1;; 43 | 2) NGINX_ENABLE=1;; 44 | 3) CRTMPD_ENABLE=1; NGINX_ENABLE=1;; 45 | *) askServers;; 46 | esac 47 | } 48 | 49 | setHostIp 50 | 51 | if [ -z $CRTMPD_ENABLE ] && [ -z $NGINX_ENABLE ]; then askServers; fi 52 | 53 | if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then . $HOME/include/core/rstream-config-crtmpd-helper;fi 54 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then . $HOME/include/core/rstream-config-nginx-helper;fi 55 | # hls only works with nginx for now. 56 | . $HOME/include/core/rstream-config-hls-helper 57 | . $HOME/include/core/rstream-config-ffmpeg-helper 58 | 59 | 60 | genConf 61 | } 62 | 63 | genConf(){ 64 | backupFile $CONFIG_FILE 65 | 66 | touch $CONFIG_FILE; 67 | 68 | if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then 69 | cat $HOME/include/templates/rstream-conf-crtmpd.tpl >> $CONFIG_FILE 70 | cat $CONFIG_FILE \ 71 | | sed s,_TAG_,$TAG,g \ 72 | | sed s,_CRTMPD_BIN_,$CRTMPD_BIN,g \ 73 | | sed s,_CRTMPD_ENABLE_,$CRTMPD_ENABLE,g \ 74 | | sed s,_CRTMPD_REGEN_CONF_,$CRTMPD_REGEN_CONF,g \ 75 | | sed s,_CRTMPD_RTMP_IP_,$CRTMPD_RTMP_IP,g \ 76 | | sed s,_CRTMPD_RTMP_PORT_,$CRTMPD_RTMP_PORT,g \ 77 | | sed s,_CRTMPD_LIVEFLV_IP_,$CRTMPD_LIVEFLV_IP,g \ 78 | | sed s,_CRTMPD_LIVEFLV_PORT_,$CRTMPD_LIVEFLV_PORT,g \ 79 | | sed s,_CRTMPD_PROXY_ENABLE_,$CRTMPD_PROXY_ENABLE,g \ 80 | | sed s,_CRTMPD_PROXY_URL_,$CRTMPD_PROXY_URL,g \ 81 | | sed s,_CRTMPD_PROXY_TRANSPARENT_,$CRTMPD_PROXY_TRANSPARENT,g \ 82 | | sed s,_CRTMPD_PROXY_LSTREAM_,$CRTMPD_PROXY_LSTREAM,g \ 83 | | sed s,_CRTMPD_PROXY_DSTREAM_,$CRTMPD_PROXY_DSTREAM,g \ 84 | > $CONFIG_FILE.tmp && mv $CONFIG_FILE.tmp $CONFIG_FILE 85 | fi 86 | 87 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then 88 | cat $HOME/include/templates/rstream-conf-nginx.tpl >> $CONFIG_FILE 89 | cat $CONFIG_FILE \ 90 | | sed s,_TAG_,$TAG,g \ 91 | | sed s,_NGINX_BIN_,$NGINX_BIN,g \ 92 | | sed s,_NGINX_ENABLE_,$NGINX_ENABLE,g \ 93 | | sed s,_NGINX_REGEN_CONF_,$NGINX_REGEN_CONF,g \ 94 | | sed s,_NGINX_RTMP_IP_,$NGINX_RTMP_IP,g \ 95 | | sed s,_NGINX_RTMP_PORT_,$NGINX_RTMP_PORT,g \ 96 | | sed s,_NGINX_RTMP_STREAM_,$NGINX_RTMP_STREAM,g \ 97 | > $CONFIG_FILE.tmp && mv $CONFIG_FILE.tmp $CONFIG_FILE 98 | fi 99 | 100 | if [ ! -z $HLS_ENABLE ] && [ $HLS_ENABLE -eq 1 ]; then 101 | cat $HOME/include/templates/rstream-conf-nginx-hls.tpl >> $CONFIG_FILE 102 | cat $CONFIG_FILE \ 103 | | sed s,_TAG_,$TAG,g \ 104 | | sed s,_HLS_ENABLE_,$HLS_ENABLE,g \ 105 | | sed s,_HLS_FQDN_,$HLS_FQDN,g \ 106 | | sed s,_HLS_TYPE_,$HLS_TYPE,g \ 107 | | sed s,_HLS_PATH_,$HLS_PATH,g \ 108 | | sed s,_HLS_WWW_,$HLS_WWW,g \ 109 | | sed s,_HLS_STREAM_,$HLS_STREAM,g \ 110 | | sed s,_TAG_,$TAG,g \ 111 | > $CONFIG_FILE.tmp && mv $CONFIG_FILE.tmp $CONFIG_FILE 112 | fi 113 | if [ ! -z $FFMPEG_ENABLE ] && [ $FFMPEG_ENABLE -eq 1 ]; then 114 | cat $HOME/include/templates/rstream-conf-ffmpeg.tpl >> $CONFIG_FILE 115 | cat $CONFIG_FILE \ 116 | | sed s,_TAG_,$TAG,g \ 117 | | sed s,_FFMPEG_ENABLE_,$FFMPEG_ENABLE,g \ 118 | | sed s,_FFMPEG_BIN_,$FFMPEG_BIN,g \ 119 | | sed s,_FFMPEG_TRANSCODER_IP_,$FFMPEG_TRANSCODER_IP,g \ 120 | | sed s,_FFMPEG_CRTMPD_ENABLE_,$FFMPEG_CRTMPD_ENABLE,g \ 121 | | sed s,_FFMPEG_NGINX_ENABLE_,$FFMPEG_NGINX_ENABLE,g \ 122 | > $CONFIG_FILE.tmp && mv $CONFIG_FILE.tmp $CONFIG_FILE 123 | fi 124 | } 125 | -------------------------------------------------------------------------------- /include/core/rstream-config-hls-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-config-hls-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | if [ ! -f $NGINX_BIN ]; then echo "!! error, nginx not found, exiting !!"; exit 99; fi 17 | 18 | logSection "* entering HLS config helper" 19 | 20 | HLS_WWW="$HOME/shared/www" 21 | HLS_FQDN="" 22 | HLS_TYPE="nginx" 23 | HLS_PATH="$HOME/tmp/nginx" 24 | askHLSSupport(){ 25 | echo -n "* Do you want to enable HTTP Live Streaming (HLS) ezez support ? [y/N]" 26 | read tmp 27 | case $tmp in 28 | y|Y) echo "-! enabling HLS"; HLS_ENABLE=1;; 29 | *) echo "-! disabling HLS"; HLS_ENABLE=0;; 30 | esac 31 | } 32 | 33 | askHLSFQDN(){ 34 | host=`hostname` 35 | echo -n "What FQDN will be serving the HLS streams [http://$hostname] ? " 36 | read tmp 37 | if [ -z $tmp ]; then HLS_FQDN="htt://$host/hls/nginx"; 38 | else HLS_FQDN=$tmp; fi 39 | } 40 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then 41 | askHLSSupport; 42 | # askHLSFQDN; 43 | else 44 | echo "-! Skipping HLS configuration (not supported without nginx)" 45 | fi 46 | -------------------------------------------------------------------------------- /include/core/rstream-config-nginx-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-config-nginx-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 15 | if [ ! -f $NGINX_BIN ]; then echo "!! error, nginx not found, exiting !!"; exit 99; fi 16 | 17 | logSection "* entering nginx-rtmp config helper" 18 | 19 | NGINX_RTMP_FQDN="" 20 | NGINX_RTMP_IP="" 21 | NGINX_RTMP_PORT="" 22 | NGINX_RTMP_IP="" 23 | NGINX_RTMP_PORT="" 24 | NGINX_REGEN_CONF="1" 25 | 26 | askRTMP(){ 27 | logHeader "General config" 28 | if [ -z $CRTMPD_RTMP_IP ]; then CRTMPD_RTMP_IP=$HOST_IP; fi 29 | 30 | if [ -z $CRTMPD_RTMP_IP ]; then tmp=$HOST_IP; else tmp=$CRTMPD_RTMP_IP; fi 31 | echo -n "What IP address should nginx-rtmp use to listen to incoming and outgoing RTMP connections [$tmp] ? " 32 | read NGINX_RTMP_IP 33 | if [ -z $NGINX_RTMP_IP ] && [ ! -z $CRTMPD_RTMP_IP ]; then NGINX_RTMP_IP=$CRTMPD_RTMP_IP; fi 34 | if [ -z $NGINX_RTMP_IP ] && [ -z $CRTMPD_RTMP_IP ]; then askRTMP; fi 35 | 36 | echo -n "What PORT should nginx-rtmp use to listen to incoming and outgoing RTMP connections on $NGINX_RTMP_IP [1935] ? " 37 | read NGINX_RTMP_PORT 38 | if [ -z $NGINX_RTMP_PORT ]; then NGINX_RTMP_PORT=1935; fi 39 | 40 | echo "" 41 | echo "** Are these settings correct ?" 42 | echo "- nginx-rtmp RTMP IP: $NGINX_RTMP_IP" 43 | echo "- nginx-rtmp RTMP PORT: $NGINX_RTMP_PORT" 44 | echo -n "[y/N] " 45 | read tmp 46 | case $tmp in 47 | y|Y) ;; 48 | *) askRTMP;; 49 | esac 50 | } 51 | if [ -z $NGINX_RTMP_IP ] || [ -z $NGINX_RTMP_PORT ]; then askRTMP; fi 52 | -------------------------------------------------------------------------------- /include/core/rstream-core: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-core 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | ## Used for log consmetics 18 | logRoute(){ 19 | echo ""; 20 | echo ">> route \"$1/$2\""; 21 | } 22 | logHeader(){ 23 | echo "** $1"; 24 | } 25 | logSection(){ 26 | echo ""; 27 | echo ">> $1" 28 | } 29 | ## Used to link configuration file $1 to path $2 (and backups $2 if it is a file) 30 | linkConf(){ 31 | # test if $2 is a file, not a symblink 32 | if [ ! -h $2 ] && [ -f $2 ]; then 33 | echo "*+ backuping file \"$1\""; 34 | backupFile $1 35 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 36 | fi 37 | if [ ! -h $2 ]; then 38 | echo "*+ linking \"$1\" to \"$2\"" 39 | ln -s $1 $2 40 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 41 | else 42 | echo "* found existing link from \"$1\" to \"$2\""; 43 | fi 44 | } 45 | 46 | 47 | 48 | 49 | 50 | #### 51 | ### Services 52 | #### 53 | setupServices(){ 54 | logHeader="services setup" 55 | OLD_IFS=$IFS; 56 | IFS=" 57 | " 58 | if [ -z $DAEMONTOOLS_SERVICE ] || [ ! -d $DAEMONTOOLS_SERVICE ]; then echo "!! error invalid DAEMONTOOLS_SERVICE \"$DAEMONTOOLS_SERVICE\", existing."; exit 99; fi 59 | # testing if link to crtmpd service exists 60 | for i in `ls -1 $HOME/var/supervise`; do 61 | daemontoolsLinkServices $i $DAEMONTOOLS_SERVICE 62 | done 63 | # if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then 64 | # fi 65 | } 66 | 67 | debugCycle(){ 68 | pauseTime=3 69 | ~rstream/bin/rstream -debug-reset && sleep $pauseTime \ 70 | && ~rstream/bin/rstream -setup crtmpd-proxy-to-nginx && sleep $pauseTime \ 71 | && ~rstream/bin/rstream -link && sleep $pauseTime \ 72 | && ~rstream/bin/rstream restart 73 | } 74 | 75 | debugReset(){ 76 | logHeader="debug reset" 77 | cmd="rm -rf $HOME/tmp" 78 | cmd="$cmd && rm -rf $HOME/var" 79 | cmd="$cmd && rm -rf $HOME/shared" 80 | cmd="$cmd && rm -f $HOME/etc/nginx*" 81 | cmd="$cmd && rm -f $HOME/etc/crtmpd*" 82 | cmd="$cmd && rm -f $DAEMONTOOLS_SERVICE/crtmpd" 83 | cmd="$cmd && rm -f $DAEMONTOOLS_SERVICE/nginx" 84 | cmd="$cmd && rm -f $DAEMONTOOLS_SERVICE/ffmpeg-*" 85 | echo -n "-! Are you sure you want to execute: [y/N] " 86 | echo $cmd; 87 | echo -n "[y/N] " 88 | read debug_confirmation 89 | case $debug_confirmation in 90 | [yY]) rstream-router "stop"; echo ""; echo "* Cleaning up.." `$cmd`;; 91 | *) echo "!! User-canceled reset" exit 1;; 92 | esac 93 | } 94 | 95 | 96 | routeHelp(){ 97 | echo "!! error, no valid argument(s) specified !" 98 | echo "-! please consult the documentation: https://github.com/kelexel/rstream"; 99 | } 100 | 101 | rstream-core-init(){ 102 | logHeader "- init checks" 103 | # check if our main $USER exists 104 | checkUser $USER $HOME; 105 | # check $HOME strucutre 106 | checkDir $HOME/etc -c $USER 755 107 | checkDir $HOME/var/log -c $USER 755 108 | checkDir $HOME/shared/media -c $USER 109 | checkDir $HOME/shared/www -c $USER 755 110 | checkDir $HOME/tmp -c 111 | } 112 | 113 | rstream-router(){ 114 | # check for config file 115 | #checkFile $HOME/etc/rstream.conf 1 116 | if [ -z $1 ]; then routeHelp; exit 1; fi 117 | case $1 in 118 | stop) 119 | daemontools-router "stop" 120 | killall -u $USER 121 | killall -TERM readproctitle supervise multilog crtmpserver 122 | ;; 123 | start) 124 | checkServiceEnabled crtmpd -nn 125 | checkServiceEnabled nginx -nn 126 | checkServiceEnabled svscan -y 127 | daemontools-router "start" 128 | rstream-router "status" 129 | ;; 130 | restart) 131 | rstream-router "stop" 132 | rstream-router "start" 133 | ;; 134 | stat|status) 135 | daemontools-router "status"; 136 | if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then crtmpd-router "status"; fi 137 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then nginx-router "status"; fi 138 | ;; 139 | -link) setupServices;; 140 | -crtmp|-crtmpd) 141 | if [ -z $2 ]; then route; exit 99; fi 142 | crtmpd-router $2 143 | ;; 144 | -nginx) 145 | if [ -z $2 ]; then route; exit 99; fi 146 | nginx-router $2 147 | ;; 148 | -daemontools|svscan) 149 | daemontools-router $2 150 | ;; 151 | -debug-cycle) debugCycle;; 152 | -debug-reset) debugReset;; 153 | -config) 154 | if [ -f $HOME/etc/rstream.conf ]; then 155 | echo "Woops found an already existing $HOME/etc/rstream.conf - backuping" 156 | backupFile $HOME/etc/rstream.conf; 157 | rstream-init 158 | fi 159 | 160 | ;; 161 | -setup|-install) 162 | if [ ! -f $HOME/etc/rstream.conf ]; then 163 | rstream-config 164 | else 165 | # rstream-router "stop" 166 | if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then 167 | crtmpd-router "setup" 168 | fi 169 | if [ ! -z $NGINX_ENABLE ] && [ $NGINX_ENABLE -eq 1 ]; then 170 | nginx-router "setup" 171 | daemontools-router "setup" 172 | fi 173 | fi 174 | ;; 175 | *) routeHelp; exit 1;; 176 | esac 177 | } -------------------------------------------------------------------------------- /include/freebsd9/rstream-freebsd9_common-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-freebsd9_common-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | ## Used to check the existence of a given username on the system 18 | checkUser(){ 19 | if [ `cat /etc/shells | grep -q "/usr/sbin/nologin" && echo $?` -eq 1 ]; then 20 | echo "*+ adding /usr/sbin/nologin to system /etc/shells" 21 | echo "/usr/sbin/nologin" >> /etc/shells 22 | fi 23 | if [ `id $1 2>&1 | grep -q 'no such user'; echo $?` -eq 0 ]; then 24 | echo "*+ adding system user \"$1\" with shell \"/sbin/nologin\" and home \"$HOME\" "; 25 | pw useradd $1 -s /usr/sbin/nologin -d $2 26 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 27 | else 28 | if [ $VERBOSE -eq 1 ]; then echo "* found system user \"$1\""; fi 29 | fi 30 | } 31 | ## Used ot check if a given file exists 32 | checkFile(){ 33 | if [ ! -f $1 ] && [ ! -z $2 ]; then echo "!! file \"$1\" not found! exiting"; exit 99; fi 34 | if [ ! -f $1 ] ; then echo "-! missing file \"$1\" !"; 35 | else echo "* found file \"$1\""; fi 36 | } 37 | 38 | ## Used to check the existence of a directory, and create it if required 39 | checkDir(){ 40 | if [ ! -d $1 ]; then 41 | if [ ! -z $2 ]; then 42 | case $2 in 43 | # -c == create 44 | "-c") 45 | echo "*+ creating \"$1\""; 46 | mkdir -p $1 47 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 48 | # check for chown arg 49 | if [ ! -z $3 ]; then 50 | if [ $VERBOSE -eq 1 ]; then echo "*+ setting ownership to \"$3\" on \"$1\""; fi 51 | chown ${3}:${3} $1 52 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 53 | fi 54 | # check chmod chown arg 55 | if [ ! -z $4 ]; then 56 | if [ $VERBOSE -eq 1 ]; then echo "*+ setting permissions to \"$4\" on \"$1\""; fi 57 | chmod ${4} $1 58 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 59 | fi 60 | ;; 61 | esac 62 | fi 63 | else 64 | if [ $VERBOSE -eq 1 ]; then echo "* found $1"; fi; 65 | fi 66 | } 67 | 68 | ## Used to check if a given portname ($1) is installed on the current system 69 | checkDependency(){ 70 | if [ ! `pkg_info | grep -q $1 && echo $?` -eq 0 ]; then echo "!! port \"$1\" is not installed on this system ! exiting.": exit 99; fi 71 | echo "* found port $1"; 72 | } 73 | 74 | checkServiceEnabled(){ 75 | test=`fgrep -q "${1}_enable=\"YES\"" /etc/rc.conf; echo $?`; 76 | if [ -z $2 ]; then 77 | if [ $test -eq 0 ]; then echo "$1 was found in system startup scripts" ; 78 | else echo "*! $1 was found in system startup scripts, exiting"; exit 99; fi 79 | else 80 | if [ $2 = "-n" ] && [ $test -eq 0 ] && [ $VERBOSE -eq 1 ]; then echo "-!"; echo "-! WARNNING, $1 was found in system startup scripts, pleas enable it!"; echo "-!"; fi 81 | if [ $2 = "-nn" ] && [ $test -eq 0 ]; then echo "-! WARNNING, $1 was found in system startup scripts, please enable it, exiting"; exit 99; fi 82 | if [ $2 = "-y" ] && [ $test -eq 1 ] && [ $VERBOSE -eq 1 ]; then echo "-!"; echo "-! WARNNING, $1 was found in system startup scripts, please remove it!"; echo "-!"; fi 83 | if [ $2 = "-yy" ] && [ $test -eq 1 ]; then echo "-! WARNNING, $1 was found in system startup scripts, please remote it, exiting"; exit 99; fi 84 | fi 85 | } 86 | ## Used to check if a given port is enabled in the system's rc.conf 87 | enableRc(){ 88 | if [ `grep -q "${1}_enable=\"YES\"" /etc/rc.conf && echo $?` -eq 1 ]; then 89 | echo "*+ enabling \"$1\" in /etc/rc.conf"; 90 | echo "$1_enable=\"YES\"" >> /etc/rc.conf 91 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 92 | else 93 | echo "* found $1 enabled in rc.conf"; 94 | fi 95 | } 96 | 97 | setHostIp(){ 98 | HOST_IP=`ifconfig 2>&1 | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print \$2}'`; 99 | echo "*+ setting HOST_IP to $HOST_IP" 100 | } 101 | 102 | 103 | backupFile(){ 104 | if [ -f $1 ]; then 105 | STAMP=`date -j -f "%a %b %d %T %Z %Y" "\`date\`" "+%s"` 106 | mv $1 $1.bak-$STAMP 107 | fi 108 | } 109 | 110 | 111 | -------------------------------------------------------------------------------- /include/freebsd9/rstream-freebsd9_crtmpd-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-freebsd9_crtmpd-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | #### 18 | ### CRTMPD setup 19 | #### 20 | crtmpdSetup(){ 21 | logHeader "crtmpd setup" 22 | checkDir $HOME/var/log/crtmpd -c $USER 23 | # check if CRTMPD_BIN is found 24 | checkFile $CRTMPD_BIN 1 25 | #set CRTMPD_CONF_TPL, if NGNIX_ENABLE=1 we must use proxypublish instead of flvplayer ! 26 | if [ -z $NGINX_ENABLE ] || [ ! $NGINX_ENABLE -eq 1 ]; then 27 | CRTMPD_CONF_TPL="$HOME/include/templates/crtmpd-conf-flvplayback.tpl" 28 | else 29 | CRTMPD_CONF_TPL="$HOME/include/templates/crtmpd-conf-proxypublish.tpl" 30 | fi 31 | if [ ! -f $CRTMPD_CONF_TPL ]; then echo "!! Invalid CRTMPD_CONF_TPL , existing. "; exit 99; fi 32 | CRTMPD_CONF="$HOME/etc/crtmpd.lua" 33 | # cosmetics 34 | if [ $CRTMPD_REGEN_CONF -eq 1 ]; then echo "-! enforcing CRTMPD_REGEN_CONF"; fi 35 | # generate CRTMPD CONF 36 | if [ $CRTMPD_REGEN_CONF -eq 1 ] || [ ! -f $HOME/etc/$CRTMPD_CONF ]; then 37 | echo "*+ generating new crtmpd conf"; 38 | # generate local nginx conf 39 | cat $CRTMPD_CONF_TPL \ 40 | | sed s,_HOME_,$HOME,g \ 41 | | sed s,_CRTMPD_RTMP_IP_,$CRTMPD_RTMP_IP,g \ 42 | | sed s,_CRTMPD_RTMP_PORT_,$CRTMPD_RTMP_PORT,g \ 43 | | sed s,_CRTMPD_PROXY_URL_,$CRTMPD_PROXY_URL,g \ 44 | | sed s,_CRTMPD_PROXY_DSTREAM_,$CRTMPD_PROXY_DSTREAM,g \ 45 | | sed s,_CRTMPD_PROXY_LSTREAM_,$CRTMPD_PROXY_LSTREAM,g \ 46 | | sed s,_CRTMPD_LIVEFLV_IP_,$CRTMPD_LIVEFLV_IP,g \ 47 | | sed s,_CRTMPD_LIVEFLV_PORT_,$CRTMPD_LIVEFLV_PORT,g \ 48 | | sed s,_PROXY_STREAM_REMOTE_,$PROXY_STREAM_REMOTE,g \ 49 | > $CRTMPD_CONF 50 | cp $HOME/include/templates/crtmpd-users.tpl $HOME/etc/crtmpd-users.lua 51 | if [ ! -z $CRTMPD_PROXY_ENABLE ] && [ $CRTMPD_PROXY_ENABLE -eq 1 ]; then 52 | echo "*+ enabling PROXY in crtmpd configuration" 53 | cat $CRTMPD_CONF \ 54 | | sed s,"--\[\[PROXY","",g \ 55 | | sed s,"PROXY\]\]--","",g \ 56 | > $CRTMPD_CONF.tmp && mv $CRTMPD_CONF.tmp $CRTMPD_CONF 57 | 58 | if [ ! -z $CRTMPD_PROXY_TRANSPARENT ] && [ $CRTMPD_PROXY_TRANSPARENT -eq 1 ]; then 59 | cat $CRTMPD_CONF \ 60 | | sed s,"--PROXY-TRANSPARENT ","",g \ 61 | > $CRTMPD_CONF.tmp && mv $CRTMPD_CONF.tmp $CRTMPD_CONF 62 | else 63 | cat $CRTMPD_CONF \ 64 | | sed s,"--PROXY-REGULAR ","",g \ 65 | > $CRTMPD_CONF.tmp && mv $CRTMPD_CONF.tmp $CRTMPD_CONF 66 | fi 67 | 68 | fi 69 | if [ ! -z $FFMPEG_CRTMPD_ENABLE ] && [ $FFMPEG_CRTMPD_ENABLE -eq 1 ]; then 70 | echo "*+ enabling TRANSCODING in crtmpd configuration" 71 | cat $CRTMPD_CONF \ 72 | | sed s,"--\[\[TRANSCODING","",g \ 73 | | sed s,"TRANSCODING\]\]--","",g \ 74 | > $CRTMPD_CONF.tmp && mv $CRTMPD_CONF.tmp $CRTMPD_CONF 75 | fi 76 | chmod 400 $CRTMPD_CONF 77 | chown $USER:$USER $CRTMPD_CONF 78 | fi 79 | 80 | # ensure that crtmps is not set in system startup 81 | checkServiceEnabled crtmpd -n 82 | 83 | # generate CRTMPD run script 84 | checkDir $HOME/var/supervise/crtmpd/log -c $USER 755 85 | #if [ $CRTMPD_REGEN_CONF -eq 1 ]; then echo "-! enforcing regen_conf"; fi 86 | # generate crtmpd/run script 87 | echo "*+ generating new crtmpd/run script"; 88 | cat $HOME/include/templates/crtmpd-run.tpl \ 89 | | sed s,_CRTMPD_BIN_,$CRTMPD_BIN,g \ 90 | | sed s,_CRTMPD_CONF_,$CRTMPD_CONF,g \ 91 | | sed s,_USER_,$USER,g \ 92 | > $HOME/var/supervise/crtmpd/run 93 | chmod 755 $HOME/var/supervise/crtmpd/run 94 | # generate crtmpd/log/run script 95 | echo "*+ generating new crtmpd/log/run script"; 96 | cat $HOME/include/templates/crtmpd-run-log.tpl \ 97 | | sed s,_USER_,$USER,g \ 98 | | sed s,_LOG_DIR_,$HOME/var/log/crtmpd,g \ 99 | > $HOME/var/supervise/crtmpd/log/run 100 | chmod 755 $HOME/var/supervise/crtmpd/log/run 101 | } 102 | 103 | #### 104 | ### CRTMPD router 105 | #### 106 | crtmpd-router(){ 107 | if [ -z $1 ]; then routeHelp; exit 1; fi 108 | logRoute "crtmpd" $1 109 | if [ -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 0 ]; then return; fi 110 | 111 | if [ -z $DAEMONTOOLS_SERVICE ] || [ ! -d $DAEMONTOOLS_SERVICE ]; then echo "!! error invalid DAEMONTOOLS_SERVICE \"$DAEMONTOOLS_SERVICE\", existing."; exit 99; fi 112 | case $1 in 113 | setup) 114 | crtmpdSetup 115 | ;; 116 | status|stat) 117 | echo "* checking if crtmpd service is running" 118 | svstat $DAEMONTOOLS_SERVICE/crtmpd 119 | svstat $DAEMONTOOLS_SERVICE/crtmpd/log 120 | ;; 121 | stop) 122 | echo "* stopping crtmpd service" 123 | svc -d $DAEMONTOOLS_SERVICE/crtmpd 124 | svc -d $DAEMONTOOLS_SERVICE/crtmpd/log 125 | crtmpd-router "status" 126 | ;; 127 | start) 128 | echo "* starting crtmpd service" 129 | svc -u $DAEMONTOOLS_SERVICE/crtmpd 130 | svc -u $DAEMONTOOLS_SERVICE/crtmpd/log 131 | echo "* waiting 5seconds ..." 132 | sleep 5 133 | crtmpd-router "status" 134 | ;; 135 | restart) 136 | crtmpd-router "stop" 137 | crtmpd-router "start" 138 | ;; 139 | test) 140 | echo "* testing crtmpd, hit ctrl+c to abort" 141 | $HOME/var/supervise/crtmpd/run 142 | ;; 143 | *) 144 | routeHelp 145 | ;; 146 | esac 147 | } -------------------------------------------------------------------------------- /include/freebsd9/rstream-freebsd9_daemontools-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-freebsd9_daemontools-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | #### 18 | ### daemontools Setup 19 | #### 20 | daemontoolsSetup(){ 21 | logHeader "daemontools setup" 22 | # check if daemontools is installed 23 | checkDependency "daemontools" 24 | # check if services exist 25 | checkDir $DAEMONTOOLS_SERVICE -rc 26 | # enable daemontools 27 | enableRc "svscan" 28 | } 29 | 30 | 31 | #### 32 | ### daemontools Link Services 33 | #### 34 | daemontoolsLinkServices(){ 35 | if [ ! -h $2/$1 ]; then 36 | echo "*+ creating service link for \"$1\" in \"$2\""; 37 | ln -s $HOME/var/supervise/$1 $2/ 38 | if [ ! $? -eq 0 ]; then echo "!! error !!"; exit 99; fi 39 | else 40 | echo "* found daemontools service in $2/$1"; 41 | fi 42 | } 43 | 44 | #### 45 | ### daemontools Router 46 | #### 47 | daemontools-router(){ 48 | if [ -z $1 ]; then routeHelp; exit 1; fi 49 | logRoute "daemontools" $1 50 | case $1 in 51 | setup) daemontoolsSetup;; 52 | status|stat) 53 | echo "* checking if svscan is running" 54 | service svscan status 55 | ;; 56 | stop) 57 | echo "* stopping svscan" 58 | service svscan stop 59 | ;; 60 | start) 61 | echo "* starting svscan" 62 | service svscan start 63 | echo "** Sleeping 5 seconds..." 64 | sleep 5 65 | ;; 66 | restart) 67 | daemontools-router "stop" 68 | daemontools-router "start" 69 | ;; 70 | *) routeHelp;; 71 | esac 72 | } 73 | 74 | -------------------------------------------------------------------------------- /include/freebsd9/rstream-freebsd9_ffmpeg-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-freebsd9_ffmpeg-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ###################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | 18 | ffmpegServiceCreate() { 19 | if [ -z $1 ]; then echo "!! missing stream name, exiting !!"; exit 99; fi 20 | stream=$1 21 | checkDir $HOME/var/log/ffmpeg -c rstream 700 22 | checkDir $HOME/var/supervise/ffmpeg-nginx-${stream}/log -c rstream 755 23 | echo "*+ generating new ffmpeg/run script for stream \"$stream\""; 24 | cat $HOME/include/templates/ffmpeg-run.tpl \ 25 | | sed s,_HOME_,$HOME,g \ 26 | | sed s,_USER_,$USER,g \ 27 | | sed s,_STREAM_,$stream,g \ 28 | | sed s,_DAEMON_,'nginx',g \ 29 | > $HOME/var/supervise/ffmpeg-nginx-${stream}/run 30 | chmod 755 $HOME/var/supervise/ffmpeg-nginx-${stream}/run 31 | echo "*+ generating new ffmpeg/run/log script for stream \"$stream\""; 32 | cat $HOME/include/templates/ffmpeg-run-log.tpl \ 33 | | sed s,_HOME_,$HOME,g \ 34 | | sed s,_USER_,$USER,g \ 35 | > $HOME/var/supervise/ffmpeg-nginx-${stream}/log/run 36 | chmod 755 $HOME/var/supervise/ffmpeg-nginx-${stream}/log/run 37 | } 38 | 39 | ffmpeg-router() { 40 | if [ -z $1 ]; then routeHelp; exit 1; fi 41 | logRoute "ffmpeg" $1 42 | if [ -z $FFMPEG_ENABLE ] || [ ! $FFMPEG_ENABLE -eq 1 ]; then break; fi 43 | 44 | case $1 in 45 | create) ffmpegServiceCreate $2;; 46 | link) rstream-router "-link";; 47 | esac 48 | } -------------------------------------------------------------------------------- /include/freebsd9/rstream-freebsd9_nginx-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ###################################################################################### 3 | ### rstream-freebsd9_nginx-helper 4 | # 5 | # license: GPL 6 | # 7 | # authors: 8 | # - Rudolph Sand aka https://github.com/kelexel 9 | # 10 | # url: 11 | # - https://github.com/kelexel/rstream 12 | # 13 | ####################################################################################### 14 | 15 | if [ -z $TAG ]; then echo "!! Error you are not supposed to execute this file directly"; exit 2; fi 16 | 17 | #### 18 | ### Nginx setup 19 | #### 20 | nginxSetup(){ 21 | logHeader "nginx setup" 22 | # test if nginx is installed 23 | checkDependency "nginx" 24 | nginx_bin=`which nginx` # should result in /usr/local/bin/nginx 25 | # test if nginx was compiled with nginx-rtmp support 26 | if [ ! `$nginx_bin -V 2>&1 | grep -q rtmp; echo $?` -eq 0 ]; then echo "!! nginx was not compiled with nginx-rtmp support , existing."; exit 99; fi 27 | echo "* found nginx-rtmp support"; 28 | # test if nginx was compiled with nginx-rtmp/hls support 29 | if [ ! -z $HLS_ENABLE ] && [ $HLS_ENABLE -eq 1 ] && [ ! `$nginx_bin -V 2>&1 | grep -q hls; echo $?` -eq 0 ]; then echo "!! nginx was not compiled with nginx-rtmp/hls support , existing."; exit 99; 30 | else if [ ! -z $HLS_ENABLE ] && [ $HLS_ENABLE -eq 1 ]; then echo "* found nginx-rtmp/hls support"; fi 31 | fi 32 | checkDir $HOME/var/log/nginx -c www 755 33 | checkDir $HOME/shared/www/stats -c www 777 34 | checkDir /var/tmp/nginx/ -c www 777 35 | 36 | # copy xsl template 37 | cp $HOME/include/templates/nginx-rtmp-stat.xsl $HOME/shared/www/stats/stat.xsl 38 | #checkDir $HOME/var/log/nginx-crtmpd-ffmpeg -c $USER 39 | 40 | if [ ! -z $HLS_ENABLE ] && [ ! -z $HLS_TYPE ] && [ $HLS_TYPE = "nginx" ]; then checkDir $HOME/tmp/nginx/hls -c www 777; fi 41 | 42 | # set nginx_conf to default FreeBSD nginx port config location 43 | LINKED_CONF="/usr/local/etc/nginx/nginx.conf" 44 | NGINX_CONF="$HOME/etc/nginx-rtmp.conf" 45 | # set NGINX_CONF_TPL based on $NGINX_HLS 46 | NGINX_CONF_TPL=${HOME}/include/templates/nginx-conf.tpl 47 | if [ $NGINX_REGEN_CONF -eq 1 ]; then echo "-! enforcing NGINX_REGEN_CONF"; fi 48 | if [ $NGINX_REGEN_CONF -eq 1 ] || [ ! -f $NGINX_CONF ]; then 49 | echo "*+ generating new nginx conf"; 50 | # generate local nginx conf 51 | cat $NGINX_CONF_TPL \ 52 | | sed s,_HOME_,$HOME,g \ 53 | | sed s,_NGINX_RTMP_IP_,$NGINX_RTMP_IP,g \ 54 | | sed s,_NGINX_RTMP_PORT_,$NGINX_RTMP_PORT,g \ 55 | | sed s,_NGINX_RTMP_STREAM_,$NGINX_RTMP_STREAM,g \ 56 | > $NGINX_CONF 57 | fi 58 | 59 | # copy mime types 60 | cp $HOME/include/templates/nginx-rtmp-mime-types.tpl $HOME/etc/nginx-rtmp-mime.types 61 | 62 | # only make the following tests if NGINX_HLS is set to 1 63 | if [ $HLS_ENABLE ] && [ ! -z $HLS_TYPE ] && [ $HLS_TYPE = "nginx" ]; then 64 | echo "*+ enabling HLS in nginx configuration" 65 | cat $NGINX_CONF \ 66 | | sed s,_HLS_ENABLE_,$HLS_ENABLE,g \ 67 | | sed s,_HLS_FQDN_,$HLS_FQDN,g \ 68 | | sed s,_HLS_TYPE_,$HLS_TYPE,g \ 69 | | sed s,_HLS_WWW_,$HLS_WWW,g \ 70 | | sed s,_HLS_PATH_,$HLS_PATH,g \ 71 | | sed s,_HLS_STREAM_,$HLS_STREAM,g \ 72 | | sed s,"#HLS","",g \ 73 | > $NGINX_CONF.tmp && mv $NGINX_CONF.tmp $NGINX_CONF 74 | fi 75 | if [ $FFMPEG_ENABLE ]; then 76 | echo "*+ enabling TRANSCODING in nginx configuration" 77 | FFMPEG_NGINX_TRANSCODING=1 78 | cat $NGINX_CONF \ 79 | | sed s,_FFMPEG_TRANSCODER_IP_,$FFMPEG_TRANSCODER_IP,g \ 80 | | sed s,_FFMPEG_NGINX_TRANSCODING_,$FFMPEG_NGINX_TRANSCODING,g \ 81 | | sed s,"#TRANSCODING","",g \ 82 | > $NGINX_CONF.tmp && mv $NGINX_CONF.tmp $NGINX_CONF 83 | fi 84 | if [ ! -z $CRTMPD_ENABLE ] && [ $CRTMPD_ENABLE -eq 1 ]; then 85 | echo "*+ enabling TRANSCODING in nginx configuration" 86 | FFMPEG_NGINX_TRANSCODING=1 87 | cat $NGINX_CONF \ 88 | | sed s,"#PROXYLOCALHOST","",g \ 89 | > $NGINX_CONF.tmp && mv $NGINX_CONF.tmp $NGINX_CONF 90 | fi 91 | checkDir /var/tmp/nginx -c www 777 92 | 93 | checkServiceEnabled nginx -n 94 | 95 | # generate NGINX run script 96 | checkDir $HOME/var/supervise/nginx/log -c $USER 755 97 | # generate nginx/run script 98 | echo "*+ generating new nginx/run script"; 99 | cat $HOME/include/templates/nginx-run.tpl \ 100 | | sed s,_NGINX_BIN_,$NGINX_BIN,g \ 101 | > $HOME/var/supervise/nginx/run 102 | chmod 755 $HOME/var/supervise/nginx/run 103 | # generate nginx/log/run script 104 | echo "*+ generating new nginx/log/run script"; 105 | cat $HOME/include/templates/nginx-run-log.tpl \ 106 | | sed s,_USER_,'www',g \ 107 | | sed s,_LOG_DIR_,$HOME/var/log/nginx,g \ 108 | > $HOME/var/supervise/nginx/log/run 109 | chmod 755 $HOME/var/supervise/nginx/log/run 110 | } 111 | #### 112 | ### CRTMPD router 113 | #### 114 | nginx-router(){ 115 | if [ -z $1 ]; then routeHelp; exit 1; fi 116 | logRoute "nginx" $1 117 | if [ -z $NGINX_ENABLE ] || [ ! $NGINX_ENABLE -eq 1 ]; then break; fi 118 | 119 | case $1 in 120 | setup) 121 | nginxSetup 122 | ;; 123 | status|stat) 124 | echo "* checking if nginx is running" 125 | svstat $DAEMONTOOLS_SERVICE/nginx 126 | svstat $DAEMONTOOLS_SERVICE/nginx/log 127 | ;; 128 | stop) 129 | echo "* stopping nginx" 130 | svc -d $DAEMONTOOLS_SERVICE/nginx 131 | svc -d $DAEMONTOOLS_SERVICE/nginx/log 132 | if [ ! -z $HLS_ENABLE ] && [ $HLS_ENABLE -eq 1 ]; then nginx-router "hls-flush"; fi 133 | ;; 134 | start) 135 | echo "* starting nginx" 136 | svc -u $DAEMONTOOLS_SERVICE/nginx 137 | svc -u $DAEMONTOOLS_SERVICE/nginx/log 138 | sleep 5 139 | nginx-router "status" 140 | ;; 141 | restart) 142 | nginx-router "stop" 143 | nginx-router "start" 144 | ;; 145 | hls-flush) 146 | echo "* flushing hls directory" 147 | rm -f $HOME/tmp/nginx/hls/*.ts 148 | rm -f $HOME/tmp/nginx/hls/*.m3u8 149 | ;; 150 | test) 151 | echo "* testing nginx, hit ctrl+c to abort" 152 | $HOME/var/supervise/nginx/run 153 | ;; 154 | *) 155 | routeHelp 156 | ;; 157 | esac 158 | } -------------------------------------------------------------------------------- /include/templates/crtmpd-conf-flvplayback.tpl: -------------------------------------------------------------------------------- 1 | -- Start of the configuration. This is the only node in the config file. 2 | -- The rest of them are sub-nodes 3 | configuration= 4 | { 5 | daemon=false, 6 | pathSeparator="/", 7 | logAppenders= 8 | { 9 | { 10 | name="console appender", 11 | type="coloredConsole", 12 | level=6 13 | }, 14 | }, 15 | applications= 16 | { 17 | rootDirectory="applications", 18 | { 19 | description="FLV Playback Sample", 20 | name="flvplayback", 21 | protocol="dynamiclinklibrary", 22 | mediaFolder="_HOME_/shared/media", 23 | aliases={ 24 | "proxy", "r", 25 | }, 26 | acceptors = 27 | { 28 | { 29 | ip="_CRTMPD_RTMP_IP_", 30 | port=_CRTMPD_RTMP_PORT_, 31 | protocol="inboundRtmp" 32 | }, 33 | --[[TRANSCODING{ 34 | ip="_CRTMPD_LIVEFLV_IP_", 35 | port=_CRTMPD_LIVEFLV_PORT_, 36 | protocol="inboundLiveFlv" 37 | },TRANSCODING]]-- 38 | }, 39 | abortOnConnectError=false, 40 | targetServers= 41 | { 42 | --[[PROXY{ 43 | targetUri="_CRTMPD_PROXY_URL_", 44 | targetStreamName="_CRTMPD_PROXY_DSTREAM_", 45 | localStreamName="_CRTMPD_PROXY_LSTREAM_", 46 | --emulateUserAgent="FMLE/3.0 (compatible; FMSc/1.0 http://www.rtmpd.com)" 47 | },PROXY]]-- 48 | }, 49 | authentication= 50 | { 51 | rtmp={ 52 | type="adobe", 53 | encoderAgents= 54 | { 55 | "FMLE/3.0 (compatible; FMSc/1.0)", 56 | }, 57 | usersFile="_HOME_/etc/crtmpd-users.lua", 58 | }, 59 | }, 60 | validateHandshake=false, 61 | default=false, 62 | }, 63 | }, 64 | } 65 | 66 | -------------------------------------------------------------------------------- /include/templates/crtmpd-conf-proxypublish.tpl: -------------------------------------------------------------------------------- 1 | -- Start of the configuration. This is the only node in the config file. 2 | -- The rest of them are sub-nodes 3 | configuration= 4 | { 5 | daemon=false, 6 | pathSeparator="/", 7 | logAppenders= 8 | { 9 | { 10 | name="console appender", 11 | type="coloredConsole", 12 | level=6 13 | }, 14 | }, 15 | applications= 16 | { 17 | rootDirectory="applications", 18 | { 19 | name="proxypublish", 20 | description="Application for forwarding streams to another RTMP server", 21 | protocol="dynamiclinklibrary", 22 | mediaFolder="_HOME_/shared/media", 23 | aliases={ 24 | "proxy", "broadcast", 25 | }, 26 | acceptors = 27 | { 28 | { 29 | ip="_CRTMPD_RTMP_IP_", 30 | port=_CRTMPD_RTMP_PORT_, 31 | protocol="inboundRtmp" 32 | }, 33 | }, 34 | abortOnConnectError=false, 35 | targetServers= 36 | { 37 | --[[PROXY{ 38 | targetUri="_CRTMPD_PROXY_URL_", 39 | --PROXY-REGULAR targetStreamName="_CRTMPD_PROXY_DSTREAM_", 40 | --PROXY-REGULAR localStreamName="_CRTMPD_PROXY_LSTREAM_", 41 | --PROXY-TRANSPARENT transparentStream=true, 42 | --emulateUserAgent="FMLE/3.0 (compatible; FMSc/1.0 http://www.rtmpd.com)" 43 | },PROXY]]-- 44 | }, 45 | authentication= 46 | { 47 | rtmp={ 48 | type="adobe", 49 | encoderAgents= 50 | { 51 | "FMLE/3.0 (compatible; FMSc/1.0)", 52 | }, 53 | usersFile="_HOME_/etc/crtmpd-users.lua", 54 | }, 55 | }, 56 | validateHandshake=false, 57 | default=false, 58 | }, 59 | }, 60 | } 61 | 62 | -------------------------------------------------------------------------------- /include/templates/crtmpd-run-log.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # v0.1 3 | log_user=_USER_ 4 | log_dir=_LOG_DIR_ 5 | multilog_bin=/usr/local/bin/multilog 6 | multilog_rotate_size="s10000000"; 7 | multilog_rotate_numb="n10"; 8 | 9 | exec /usr/local/bin/setuidgid $log_user \ 10 | $multilog_bin t \ 11 | $multilog_rotate_size $multilog_rotate_numb \ 12 | $log_dir 13 | -------------------------------------------------------------------------------- /include/templates/crtmpd-run.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # v0.2 3 | crtmpd_bin="_CRTMPD_BIN_" 4 | crtmpd_config="_CRTMPD_CONF_" 5 | crtmpd_user="_USER_" 6 | 7 | # needed in case we connect to nginx - to ensure nginx is fully started before we try connecting to it 8 | sleep 2 9 | exec /usr/local/bin/setuidgid $crtmpd_user $crtmpd_bin $crtmpd_debug $crtmpd_config 10 | -------------------------------------------------------------------------------- /include/templates/crtmpd-trunk-779-transparentStream.patch: -------------------------------------------------------------------------------- 1 | --- sources/applications/proxypublish/src/proxypublishapplication.cpp 2012-08-13 19:18:19.000000000 +0000 2 | +++ sources/applications/proxypublish/src/proxypublishapplication.cpp.new 2012-08-13 20:00:04.000000000 +0000 3 | @@ -281,17 +281,26 @@ 4 | FATAL("RTMP protocol not supported"); 5 | return false; 6 | #else 7 | - //1. Filter the stream 8 | - if (target.HasKey("localStreamName")) { 9 | - if (((string) target["localStreamName"]) != pStream->GetName()) { 10 | - if (pStream->GetName().find(((string) target["localStreamName"]) + "?") != 0) { 11 | - FINEST("Stream name not matching. Wanted: %s(?); Got: %s", 12 | - STR(target["localStreamName"]), 13 | - STR(pStream->GetName())); 14 | - return true; 15 | - } 16 | - } 17 | - } 18 | + // Check if transparentStream=true, if so use the current stream name as both localStreamName and targetStreamName 19 | + if (!target.HasKey("transparentStream") || !target["transparentStream"]) { 20 | + //1. Filter the stream 21 | + if (target.HasKey("localStreamName")) { 22 | + if (((string) target["localStreamName"]) != pStream->GetName()) { 23 | + if (pStream->GetName().find(((string) target["localStreamName"]) + "?") != 0) { 24 | + FINEST("Stream name not matching. Wanted: %s(?); Got: %s", 25 | + STR(target["localStreamName"]), 26 | + STR(pStream->GetName())); 27 | + return true; 28 | + } 29 | + } 30 | + } 31 | + } 32 | + // Else, if transparentStream is set to true, if so use the current stream name as both localStreamName and targetStreamName 33 | + else { 34 | + // set target["localStreamName"] based on the current streamName, so that targetStream will refflect it 35 | + target["localStreamName"] = pStream->GetName(); 36 | + WARN("TransparentStream mode enabled, using `%s` as localStreamName and targetStreamName", STR(target["localStreamName"])); 37 | + } 38 | 39 | -------------------------------------------------------------------------------- /include/templates/crtmpd-users.tpl: -------------------------------------------------------------------------------- 1 | users= 2 | { 3 | broadcast="n3rox" 4 | } 5 | 6 | realms= 7 | { 8 | { 9 | name="RStream Realm", 10 | method="Basic", 11 | users={ 12 | "broadcast" 13 | }, 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /include/templates/ffmpeg-run-log.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # v0.1 3 | log_user=_USER_ 4 | log_dir=_HOME_/var/log/ffmpeg 5 | multilog_bin=/usr/local/bin/multilog 6 | multilog_rotate_size="s10000000"; 7 | multilog_rotate_numb="n10"; 8 | 9 | exec /usr/local/bin/setuidgid $log_user \ 10 | $multilog_bin t \ 11 | $multilog_rotate_size $multilog_rotate_numb \ 12 | $log_dir 13 | -------------------------------------------------------------------------------- /include/templates/ffmpeg-run.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Delaying FFMPEG startup" 4 | sleep 5 5 | FFMPEG_SCRIPT="_HOME_/bin/rstream-transcoder -run _DAEMON_ _STREAM_" 6 | exec setuidgid stream $FFMPEG_SCRIPT 7 | -------------------------------------------------------------------------------- /include/templates/libavformat-segment-c_segment-list-EXTM3U.patch: -------------------------------------------------------------------------------- 1 | --- libavformat/segment.c.org 2012-08-16 18:23:53.000000000 +0000 2 | +++ libavformat/segment.c 2012-08-16 18:41:43.000000000 +0000 3 | @@ -34,6 +34,7 @@ 4 | typedef enum { 5 | LIST_TYPE_FLAT = 0, 6 | LIST_TYPE_EXT, 7 | + LIST_TYPE_EXTM3U, 8 | LIST_TYPE_NB, 9 | } ListType; 10 | 11 | @@ -129,7 +130,11 @@ 12 | avio_printf(seg->list_pb, "%s\n", oc->filename); 13 | } else if (seg->list_type == LIST_TYPE_EXT) { 14 | avio_printf(seg->list_pb, "%s,%f,%f\n", oc->filename, seg->start_time, seg->end_time); 15 | + } else if (seg->list_type == LIST_TYPE_EXTM3U) { 16 | + avio_printf(seg->list_pb, "#EXTINF:%s,\n",seg->time_str); 17 | + avio_printf(seg->list_pb, "%s\n", oc->filename); 18 | } 19 | + 20 | avio_flush(seg->list_pb); 21 | } 22 | 23 | @@ -238,11 +243,19 @@ 24 | if (!oc) 25 | return AVERROR(ENOMEM); 26 | 27 | - if (seg->list) 28 | + if (seg->list) { 29 | if ((ret = avio_open2(&seg->list_pb, seg->list, AVIO_FLAG_WRITE, 30 | &s->interrupt_callback, NULL)) < 0) 31 | goto fail; 32 | 33 | + if (seg->list_type == LIST_TYPE_EXTM3U) { 34 | + avio_printf(seg->list_pb, "#EXTM3U\n"); 35 | + avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%s\n",seg->time_str); 36 | + avio_printf(seg->list_pb, "#EXT-X-ALLOW-CACHE:1s\n"); 37 | + avio_printf(seg->list_pb, "\n"); 38 | + } 39 | + } 40 | + 41 | for (i = 0; i< s->nb_streams; i++) 42 | seg->has_video += 43 | (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO); 44 | @@ -369,6 +382,7 @@ 45 | { "segment_list_type", "set the segment list type", OFFSET(list_type), AV_OPT_TYPE_INT, {.dbl = LIST_TYPE_FLAT}, 0, LIST_TYPE_NB-1, E, "list_type" }, 46 | { "flat", "flat format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, 0, "list_type" }, 47 | { "ext", "extended format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_EXT }, INT_MIN, INT_MAX, 0, "list_type" }, 48 | + { "extm3u", "extended M3U format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_EXTM3U }, INT_MIN, INT_MAX, 0, "list_type" }, 49 | { "segment_time", "set segment duration", OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, 50 | { "segment_time_delta","set approximation value used for the segment times", OFFSET(time_delta_str), AV_OPT_TYPE_STRING, {.str = "0"}, 0, 0, E }, 51 | { "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, 52 | -------------------------------------------------------------------------------- /include/templates/nginx-conf.tpl: -------------------------------------------------------------------------------- 1 | 2 | user www; 3 | worker_processes 1; 4 | 5 | # required by daemontools, but already passed by the run script 6 | # daemon off; 7 | 8 | error_log stderr; 9 | 10 | events { 11 | worker_connections 1024; 12 | } 13 | 14 | 15 | rtmp { 16 | server { 17 | listen _NGINX_RTMP_IP_:_NGINX_RTMP_PORT_; 18 | chunk_size 128; 19 | publish_time_fix on; 20 | application proxy { 21 | live on; 22 | #TRANSCODING exec /bin/sh -c "_HOME_/bin/rstream-transcoder -run nginx $name"; 23 | ##TRANSCODING exec /bin/sh -c "_HOME_/bin/rstream-transcoder -run hls $name"; 24 | allow publish _NGINX_RTMP_IP_; 25 | #PROXYLOCALHOST deny publish all; 26 | allow play all; 27 | } 28 | application r { 29 | live on; 30 | #HLS hls on; 31 | #HLS hls_path _HLS_PATH_/hls; 32 | #HLS hls_fragment 5s; 33 | #TRANSCODING allow publish _FFMPEG_TRANSCODER_IP_; 34 | #TRANSCODING deny publish all; 35 | allow play all; 36 | } 37 | } 38 | } 39 | 40 | http { 41 | include _HOME_/etc/nginx-rtmp-mime.types; 42 | server { 43 | listen _NGINX_RTMP_IP_:80; 44 | location / { 45 | root _HLS_WWW_; 46 | } 47 | location /stat { 48 | rtmp_stat all; 49 | rtmp_stat_stylesheet stat.xsl; 50 | } 51 | location /stat.xsl { 52 | root _HLS_WWW_/stats/; 53 | } 54 | #HLS location /hls { 55 | #HLS root _HLS_PATH_; 56 | #HLS } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /include/templates/nginx-rtmp-mime-types.tpl: -------------------------------------------------------------------------------- 1 | 2 | types { 3 | application/x-mpegURL m3u8; 4 | video/MP2T ts; 5 | 6 | text/html html htm shtml; 7 | text/css css; 8 | text/xml xml xsl; 9 | image/gif gif; 10 | image/jpeg jpeg jpg; 11 | application/x-javascript js; 12 | application/atom+xml atom; 13 | application/rss+xml rss; 14 | 15 | text/mathml mml; 16 | text/plain txt; 17 | text/vnd.sun.j2me.app-descriptor jad; 18 | text/vnd.wap.wml wml; 19 | text/x-component htc; 20 | 21 | image/png png; 22 | image/tiff tif tiff; 23 | image/vnd.wap.wbmp wbmp; 24 | image/x-icon ico; 25 | image/x-jng jng; 26 | image/x-ms-bmp bmp; 27 | image/svg+xml svg svgz; 28 | image/webp webp; 29 | 30 | application/java-archive jar war ear; 31 | application/mac-binhex40 hqx; 32 | application/msword doc; 33 | application/pdf pdf; 34 | application/postscript ps eps ai; 35 | application/rtf rtf; 36 | application/vnd.ms-excel xls; 37 | application/vnd.ms-powerpoint ppt; 38 | application/vnd.wap.wmlc wmlc; 39 | application/vnd.google-earth.kml+xml kml; 40 | application/vnd.google-earth.kmz kmz; 41 | application/x-7z-compressed 7z; 42 | application/x-cocoa cco; 43 | application/x-java-archive-diff jardiff; 44 | application/x-java-jnlp-file jnlp; 45 | application/x-makeself run; 46 | application/x-perl pl pm; 47 | application/x-pilot prc pdb; 48 | application/x-rar-compressed rar; 49 | application/x-redhat-package-manager rpm; 50 | application/x-sea sea; 51 | application/x-shockwave-flash swf; 52 | application/x-stuffit sit; 53 | application/x-tcl tcl tk; 54 | application/x-x509-ca-cert der pem crt; 55 | application/x-xpinstall xpi; 56 | application/xhtml+xml xhtml; 57 | application/zip zip; 58 | 59 | application/octet-stream bin exe dll; 60 | application/octet-stream deb; 61 | application/octet-stream dmg; 62 | application/octet-stream eot; 63 | application/octet-stream iso img; 64 | application/octet-stream msi msp msm; 65 | 66 | audio/midi mid midi kar; 67 | audio/mpeg mp3; 68 | audio/ogg ogg; 69 | audio/x-m4a m4a; 70 | audio/x-realaudio ra; 71 | 72 | video/3gpp 3gpp 3gp; 73 | video/mp4 mp4; 74 | video/mpeg mpeg mpg; 75 | video/quicktime mov; 76 | video/webm webm; 77 | video/x-flv flv; 78 | video/x-m4v m4v; 79 | video/x-mng mng; 80 | video/x-ms-asf asx asf; 81 | video/x-ms-wmv wmv; 82 | video/x-msvideo avi; 83 | } 84 | -------------------------------------------------------------------------------- /include/templates/nginx-rtmp-stat.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | RTMP statistics 10 | 11 | 12 | 13 |
14 | Generated by NGINX RTMP module, 15 | NGINX , 16 | built   17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 49 | 50 | 51 |
RTMP#clientsIn bytesOut bytesIn KbpsOut KbpsSizeFrame RateVideoAudioStateTime
39 | 44 | 45 | 46 | 47 | 48 |
52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | live streams 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | var d=document.getElementById('-'); 85 | d.style.display=d.style.display=='none'?'':'none'; 86 | return false 87 | 88 | 89 | 90 | [EMPTY] 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | x 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | - 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
StateAddressFlash versionPage URLSWF URLDroppedA-VTime
132 | 133 | 134 |
135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | d 145 | 146 | 147 | 148 | h 149 | 150 | 151 | 152 | m 153 | 154 | 155 | s 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | publishing 185 | 186 | 187 | 188 | / 189 | 190 | 191 | 192 | / 193 | 194 | 195 |
196 | 197 | -------------------------------------------------------------------------------- /include/templates/nginx-run-log.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # v0.1 3 | log_user=_USER_ 4 | log_dir=_LOG_DIR_ 5 | multilog_bin=/usr/local/bin/multilog 6 | multilog_rotate_size="s10000000"; 7 | multilog_rotate_numb="n10"; 8 | 9 | exec /usr/local/bin/setuidgid $log_user \ 10 | $multilog_bin t \ 11 | $multilog_rotate_size $multilog_rotate_numb \ 12 | $log_dir 13 | -------------------------------------------------------------------------------- /include/templates/nginx-run.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | nginx=_NGINX_BIN_ 3 | 4 | exec $nginx -g 'daemon off;' 2>&1 5 | -------------------------------------------------------------------------------- /include/templates/rstream-conf-crtmpd.tpl: -------------------------------------------------------------------------------- 1 | ###################################################################################### 2 | ### rstream-conf-crtmpd.tpl 3 | ## tag: _TAG_ 4 | ###################################################################################### 5 | CRTMPD_ENABLE=_CRTMPD_ENABLE_ 6 | CRTMPD_BIN="_CRTMPD_BIN_" 7 | CRTMPD_RTMP_IP="_CRTMPD_RTMP_IP_" 8 | CRTMPD_RTMP_PORT="_CRTMPD_RTMP_PORT_" 9 | CRTMPD_LIVEFLV_IP="_CRTMPD_LIVEFLV_IP_" 10 | CRTMPD_LIVEFLV_PORT="_CRTMPD_LIVEFLV_PORT_" 11 | CRTMPD_PROXY_ENABLE="_CRTMPD_PROXY_ENABLE_" 12 | CRTMPD_PROXY_URL="_CRTMPD_PROXY_URL_" 13 | CRTMPD_PROXY_LSTREAM="_CRTMPD_PROXY_LSTREAM_" 14 | CRTMPD_PROXY_DSTREAM="_CRTMPD_PROXY_DSTREAM_" 15 | CRTMPD_PROXY_TRANSPARENT="_CRTMPD_PROXY_TRANSPARENT_" 16 | CRTMPD_REGEN_CONF=_CRTMPD_REGEN_CONF_ -------------------------------------------------------------------------------- /include/templates/rstream-conf-ffmpeg.tpl: -------------------------------------------------------------------------------- 1 | ###################################################################################### 2 | ### rstream-conf-ffmpeg.tpl 3 | ## tag: _TAG_ 4 | ###################################################################################### 5 | FFMPEG_ENABLE=_FFMPEG_ENABLE_ 6 | FFMPEG_BIN="_FFMPEG_BIN_" 7 | FFMPEG_TRANSCODER_IP="_FFMPEG_TRANSCODER_IP_" 8 | FFMPEG_NGINX_ENABLE=_FFMPEG_NGINX_ENABLE_ # works as of 0.4 9 | FFMPEG_CRTMPD_ENABLE=_FFMPEG_CRTMPD_ENABLE_ # barely working right now 10 | -------------------------------------------------------------------------------- /include/templates/rstream-conf-nginx-hls.tpl: -------------------------------------------------------------------------------- 1 | ###################################################################################### 2 | ### rstream-conf-nginx-hls.tpl 3 | ## tag: _TAG_ 4 | ###################################################################################### 5 | HLS_ENABLE=_HLS_ENABLE_ 6 | HLS_TYPE="_HLS_TYPE_" 7 | HLS_WWW="_HLS_WWW_" 8 | HLS_PATH="_HLS_PATH_" 9 | HLS_FQDN="_HLS_FQDN_" -------------------------------------------------------------------------------- /include/templates/rstream-conf-nginx.tpl: -------------------------------------------------------------------------------- 1 | ###################################################################################### 2 | ### rstream-conf-nginx.tpl 3 | ## tag: _TAG_ 4 | ###################################################################################### 5 | NGINX_BIN="_NGINX_BIN_" 6 | NGINX_ENABLE=_NGINX_ENABLE_ 7 | NGINX_RTMP_IP="_NGINX_RTMP_IP_" 8 | NGINX_RTMP_PORT="_NGINX_RTMP_PORT_" 9 | NGINX_REGEN_CONF=_NGINX_REGEN_CONF_ -------------------------------------------------------------------------------- /include/templates/rstream-firewall.dist: -------------------------------------------------------------------------------- 1 | ###################################################################################### 2 | ### rstream-firewal.dist 3 | # 4 | # license: GPL 5 | # 6 | # authors: 7 | # - Rudolph Sand aka https://github.com/kelexel 8 | # 9 | # url: 10 | # - https://github.com/kelexel/rstream 11 | # 12 | # purpose: 13 | # - Firewalls ONE or SEVERAL IPs on a SINGLE ETHERNET ADAPTER *BSD System 14 | # 15 | # disclaimer: 16 | # - Only play with this script if you have a (physical|virtual) way to reboot the box, or best case scenario a KVM(IP)/IPMI plugged to it ;) 17 | # - This script comes as is, USE AT YOUR OWN RISKS 18 | # 19 | # prerequisits: 20 | # - # set pf_enable="YES" in /etc/rc.conf 21 | # - # copy this dist file under /etc/pf.conf (make backups if necessary !!!) 22 | # Warning - bellow this point you are going to start PF; if you are connected to your server via SSH, your connection will be closed. 23 | # This is *in theory* normal. 24 | # Just re-connect to your server via SSH right after issuing the following command: 25 | # - # service pf start 26 | # 27 | # 28 | ###################################################################################### 29 | # 30 | 31 | # These are the PUBLIC IPs set on the PUBLIC INTERFACE of your server 32 | host_ip = "{ 1.2.3.4 2.3.3.2 }" 33 | 34 | # don't filter lo ! 35 | set skip on lo 36 | 37 | # block everything in 38 | block in all 39 | 40 | # permit everything out 41 | pass out all 42 | 43 | # pass all icmp in / out 44 | pass proto { icmp icmp6 } 45 | 46 | # allow http in 47 | pass in proto tcp to $host_ip port { http https } 48 | # allow ssh in 49 | pass in proto tcp to $host_ip port { ssh } 50 | # allow rtmp in 51 | pass in proto tcp to $host_ip port { 1935 1936 } -------------------------------------------------------------------------------- /include/templates/stat.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | RTMP statistics 10 | 11 | 12 | 13 |
14 | Generated by NGINX RTMP module, 15 | NGINX , 16 | built   17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 49 | 50 | 51 |
RTMP#clientsIn bytesOut bytesIn KbpsOut KbpsSizeFrame RateVideoAudioStateTime
39 | 44 | 45 | 46 | 47 | 48 |
52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | live streams 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | var d=document.getElementById('-'); 85 | d.style.display=d.style.display=='none'?'':'none'; 86 | return false 87 | 88 | 89 | 90 | [EMPTY] 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | x 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | - 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
StateAddressFlash versionPage URLSWF URLDroppedA-VTime
132 | 133 | 134 |
135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | d 145 | 146 | 147 | 148 | h 149 | 150 | 151 | 152 | m 153 | 154 | 155 | s 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | publishing 185 | 186 | 187 | 188 | / 189 | 190 | 191 | 192 | / 193 | 194 | 195 |
196 | 197 | --------------------------------------------------------------------------------