Simple-RTMP-Server
==================
SRS(SIMPLE RTMP Server) over state-threads created in 2013.
SRS is a simple, RTMP/HLS, high-performance, single(plan)/multiple processes, edge(plan)/origin live server.
SRS supports [vhost](https://github.com/winlinvip/simple-rtmp-server/wiki/RtmpUrlVhost), rtmp, [HLS](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryHLS), transcoding, forward, [http hooks](https://github.com/winlinvip/simple-rtmp-server/wiki/HTTPCallback).
Blog: [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin)
See also: [https://github.com/winlinvip/simple-rtmp-server](https://github.com/winlinvip/simple-rtmp-server)
See also: [http://winlinvip.github.io/simple-rtmp-server](http://winlinvip.github.io/simple-rtmp-server)
TencentQQ: [http://url.cn/WAHICw](http://url.cn/WAHICw) (Group: 212189142)
### AUTHORS
The PRIMARY AUTHORS are (and/or have been)(Authors ordered by first contribution):
* winlin([winterserver](#)): [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin)
* wenjie([wenjiegit](https://github.com/wenjiegit/simple-rtmp-server)): [http://blog.chinaunix.net/uid/25006789.html](http://blog.chinaunix.net/uid/25006789.html)
About the primary AUTHORS:
* Contribute important features to SRS.
* Names of all PRIMARY AUTHORS response in NetConnection.connect and metadata.
And here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS --
people who have submitted patches, reported bugs, added translations, helped
answer newbie questions, and generally made SRS that much better: [AUTHORS.txt](https://github.com/winlinvip/simple-rtmp-server/blob/master/AUTHORS.txt)
### Wiki
[https://github.com/winlinvip/simple-rtmp-server/wiki](https://github.com/winlinvip/simple-rtmp-server/wiki)
### Usage(RTMP) for RTMP only
Requires: Centos6.x 64bits, others see [Build](https://github.com/winlinvip/simple-rtmp-server/wiki/Build)
Step 0: get SRS
git clone https://github.com/winlinvip/simple-rtmp-server && cd simple-rtmp-server/trunkStep 1: build SRS
./configure --with-ssl --without-hls --without-ffmpeg --without-http && makeStep 2: start SRS
./objs/srs -c conf/srs.confStep 3: [Adobe FMLE](http://www.adobe.com/cn/products/flash-media-encoder.html) publish demo live stream
FMS URL: rtmp://192.168.1.170/live Stream: livestreamStep 4: [VLC (2.1+)](http://www.videolan.org/vlc/) play live stream.
rtmp url: rtmp://192.168.1.170/live/livestream### Usage(simple) for all features Requires: Centos6.x 64bits, others see [Build](https://github.com/winlinvip/simple-rtmp-server/wiki/Build)
git clone https://github.com/winlinvip/simple-rtmp-server && cd simple-rtmp-server/trunkStep 0: build SRS system.
bash scripts/build.shStep 1: start SRS all demo features.
bash scripts/run.shStep 2: SRS live show: [http://your-server-ip](http://your-server-ip)
bash scripts/stop.sh### Usage(detail) for all features Requires: Centos6.x 64bits, others see [Build](https://github.com/winlinvip/simple-rtmp-server/wiki/Build)
git clone https://github.com/winlinvip/simple-rtmp-server && cd simple-rtmp-server/trunkStep 1: build SRS
./configure --with-ssl --with-hls --with-ffmpeg --with-http && makeStep 2: start SRS
./objs/srs -c conf/srs.confStep 3(optinal): start SRS listen at 19350 to forward to
./objs/srs -c conf/srs.19350.confStep 4(optinal): start nginx for HLS
sudo ./objs/nginx/sbin/nginxStep 5(optinal): start http hooks for SRS callback
python ./research/api-server/server.py 8085Step 6: publish demo live stream
FMS URL: rtmp://127.0.0.1/live?vhost=demo.srs.com
Stream: livestream
FFMPEG to publish the default demo stream:
for((;;)); do \
./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
-vcodec copy -acodec copy \
-f flv -y rtmp://127.0.0.1/live?vhost=demo.srs.com/livestream; \
sleep 1; \
done
Step 7: publish players live stream
FMS URL: rtmp://127.0.0.1/live?vhost=players
Stream: livestream
FFMPEG to publish the players demo stream:
for((;;)); do \
./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
-vcodec copy -acodec copy \
-f flv -y rtmp://127.0.0.1/live?vhost=players/livestream; \
sleep 1; \
done
Step 8: add server ip to client hosts as demo. # edit the folowing file: # linux: /etc/hosts # windows: C:\Windows\System32\drivers\etc\hosts # where server ip is 192.168.2.111 192.168.2.111 demo.srs.comStep 9: play live stream.
players: http://demo.srs.com/players rtmp url: rtmp://demo.srs.com/live/livestream m3u8 url: http://demo.srs.com/live/livestream.m3u8 for android: http://demo.srs.com/live/livestream.htmlStep 10(optinal): play live stream auto transcoded
rtmp url: rtmp://demo.srs.com/live/livestream_ld m3u8 url: http://demo.srs.com/live/livestream_ld.m3u8 for android: http://demo.srs.com/live/livestream_ld.html rtmp url: rtmp://demo.srs.com/live/livestream_sd m3u8 url: http://demo.srs.com/live/livestream_sd.m3u8 for android: http://demo.srs.com/live/livestream_sd.htmlStep 11(optinal): play live stream auto forwarded, the hls dir change to /forward
rtmp url: rtmp://demo.srs.com:19350/live/livestream m3u8 url: http://demo.srs.com/forward/live/livestream.m3u8 for android: http://demo.srs.com/forward/live/livestream.html rtmp url: rtmp://demo.srs.com:19350/live/livestream_ld m3u8 url: http://demo.srs.com/forward/live/livestream_ld.m3u8 for android: http://demo.srs.com/forward/live/livestream_ld.html rtmp url: rtmp://demo.srs.com:19350/live/livestream_sd m3u8 url: http://demo.srs.com/forward/live/livestream_sd.m3u8 for android: http://demo.srs.com/forward/live/livestream_sd.htmlStep 12(optinal): modify the config and reload it (all features support reload)
killall -1 srsor use specified signal to reload:
killall -s SIGHUP srs### Architecture System Architecture:
+------------------------------------------------------+ | SRS(Simple RTMP Server) | +---------------+---------------+-----------+----------+ | API/hook | Transcoder | HLS | RTMP | | http-parser | FFMPEG/x264 | NGINX/ts | protocol | +---------------+---------------+-----------+----------+ | Network(state-threads) | +------------------------------------------------------+ | All Linux(RHEL,CentOS,Ubuntu,Fedora...) | +------------------------------------------------------+Modularity Architecture:
+------------------------------------------------------+ | Main(srs/bandwidth/librtmp) | +------------------------------------------------------+ | App(Server/Client application) | +------------------------------------------------------+ | RTMP(Protocol stack) | +------------------------------------------------------+ | Kernel(depends on Core, provides error/log) | +------------------------------------------------------+ | Core(depends only on system apis) | +------------------------------------------------------+Stream Architecture:
+---------+ +----------+
+ Publish + + Deliver |
+---|-----+ +----|-----+
+-----------+-------------------------+----------------+
| Encoder | SRS(Simple RTMP Server) | Client |
+-----------+-------------------------+----------------+
| (FMLE, | +-> RTMP protocol ----+-> Flash Player |
| FFMPEG, --+-> +-> HLS/NGINX --------+-> m3u8 player |
| Flash, | +-> Fowarder ---------+-> RTMP Server |
| XSPLIT, | +-> Transcoder -------+-> RTMP Server |
| ...) | +-> DVR --------------+-> FILE |
| | +-> BandwidthTest ----+-> Flash/StLoad |
+-----------+-------------------------+----------------+
(plan) RTMP cluster(origin/edge) Architecture:
+---------+ +-----------------+ +-----------------------+
+ Encoder +--+-->-+ SRS(RTMP Edge) +--->-+ (RTMP Origin) |
+---------+ | +-----------------+ | SRS/FMS/NGINX-RTMP |
| | Red5/HELIX/CRTMP |
+-------------------------->-+ ...... |
+-----------------------+
Schema#1: Any RTMP encoder push RTMP stream to RTMP (origin/edge)server,
where SRS RTMP Edge server will forward stream to origin.
+-------------+ +-----------------+ +--------------------+
| RTMP Origin +-->-+ SRS(RTMP Edge) +--+->-+ Client(RTMP/HLS) |
+-------------+ +-----------------+ | | Flash/IOS/Android |
| +--------------------+
|
| +-----------------+
+->-+ SRS(RTMP Edge) +
+-----------------+
Schema#2: SRS RTMP Edge server pull stream from origin (or upstream SRS
RTMP Edge server), then delivery to Client.
(plan) SRS Multiple processes Architecture:
+---------------------------+
+-----+ worker process(3) |
+----------------+ | +---------------------------+
| master process |---(2)---+
| (1)manager | | +---------------------------+
+----------------+ +-----+ worker process N |
| +---------------------------+
|
| +---------------------------+
+-----+ bandwidth test process(4) |
+---------------------------+
Remark:
(1) master process: to fork processes, schedule fd(client) to the "right"
process, forward messages between processes
(2) communication: master process use unix domain socket to communicate
with worker processes.
(3) worker process: to provide RTMP streaming service, generate HLS files.
(4) bandwidth test process: for all bandwidth test request, to make the
bandwidth testing has minimal effect to streaming service
Bandwidth Test Workflow:
+------------+ +----------+
| Client | | Server |
+-----+------+ +-----+----+
| |
| connect vhost-------------> |
| <-----------result(success) |
| |
| <----------call(start play) |
| result(playing)----------> |
| <-------------data(playing) |
| <-----------call(stop play) |
| result(stopped)----------> |
| |
| <-------call(start publish) |
| result(publishing)-------> |
| data(publishing)---------> |
| <--------call(stop publish) |
| result(stopped)(1)-------> |
| |
| <--------------------report |
| final(2)-----------------> |
| <END> |
@See: class SrsBandwidth comments.
### System Requirements
Supported operating systems and hardware:
* All Linux , both 32 and 64 bits
* All handware.
### Summary
1. Simple: also stable enough.[winlin@dev6 srs]$ dstat ----total-cpu-usage---- -dsk/total- ---net/lo-- ---paging-- ---system-- usr sys idl wai hiq siq| read writ| recv send| in out | int csw 58 9 32 0 0 1| 0 4168k| 277M 277M| 0 0 | 29k 25k 61 8 30 0 0 1| 0 1168k| 336M 336M| 0 0 | 29k 24k 63 8 27 0 0 1| 0 2240k| 124M 124M| 0 0 | 32k 33k 62 8 28 0 0 1| 0 1632k| 110M 110M| 0 0 | 31k 33k 53 7 40 0 0 1| 0 1360k| 115M 115M| 0 0 | 24k 26k 51 7 41 0 0 1| 0 1184k| 146M 146M| 0 0 | 24k 27k 39 6 54 0 0 1| 0 1284k| 105M 105M| 0 0 | 22k 28k 41 6 52 0 0 1| 0 1264k| 116M 116M| 0 0 | 25k 28k 48 6 45 0 0 1| 0 1272k| 143M 143M| 0 0 | 27k 27kSee also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-server/wiki/Performance) ### Releases * 2013-12-25, [Release v0.9](https://github.com/winlinvip/simple-rtmp-server/releases/tag/0.9), support bandwidth test, player/encoder/chat demos. 20926 lines.