nginx-mod-rtmp/README.md

321 lines
8.4 KiB
Markdown
Raw Normal View History

2013-11-28 11:20:09 +01:00
# NGINX-based Media Streaming Server
2012-08-20 06:40:23 +02:00
## nginx-rtmp-module
2012-08-20 06:36:32 +02:00
2012-11-16 14:27:35 +01:00
### Project blog
2012-08-20 06:36:32 +02:00
2013-06-24 10:07:38 +02:00
http://nginx-rtmp.blogspot.com
2012-08-20 06:36:32 +02:00
2012-11-16 14:27:35 +01:00
### Wiki manual
2012-08-20 06:36:32 +02:00
2012-09-25 07:05:06 +02:00
https://github.com/arut/nginx-rtmp-module/wiki/Directives
2012-08-20 06:36:32 +02:00
2012-11-16 14:20:12 +01:00
### Google group
https://groups.google.com/group/nginx-rtmp
https://groups.google.com/group/nginx-rtmp-ru (Russian)
2013-06-18 12:42:40 +02:00
### Donation page (Paypal etc)
2012-11-17 12:57:18 +01:00
http://arut.github.com/nginx-rtmp-module/
2012-11-16 14:27:35 +01:00
### Features
2012-08-20 06:36:32 +02:00
* Live streaming of video/audio
2012-11-16 14:20:12 +01:00
* Video on demand FLV/MP4,
playing from local filesystem or HTTP
2012-08-20 06:36:32 +02:00
* Stream relay support for distributed
streaming: push & pull models
2012-09-25 07:05:06 +02:00
* Recording streams in multiple FLVs
2012-08-20 06:36:32 +02:00
* H264/AAC support
* Online transcoding with FFmpeg
2013-03-22 05:51:22 +01:00
* HLS (HTTP Live Streaming) support
2012-08-20 06:36:32 +02:00
2012-11-16 14:20:12 +01:00
* HTTP callbacks (publish/play/record/update etc)
2012-09-25 07:05:06 +02:00
* Running external programs on certain events (exec)
2012-08-20 06:36:32 +02:00
2012-11-16 14:20:12 +01:00
* HTTP control module for recording audio/video and dropping clients
2012-08-20 06:36:32 +02:00
* Advanced buffering techniques
to keep memory allocations at a minimum
level for faster streaming and low
memory footprint
* Proved to work with Wirecast,FMS,Wowza,
JWPlayer,FlowPlayer,StrobeMediaPlayback,
2013-11-30 08:21:53 +01:00
ffmpeg,avconv,rtmpdump,flvstreamer
2012-08-20 06:36:32 +02:00
and many more
* Statistics in XML/XSL in machine- & human-
readable form
2013-06-13 15:22:17 +02:00
* Linux/FreeBSD/MacOS/Windows
2012-09-25 07:05:06 +02:00
2012-11-16 14:27:35 +01:00
### Build
2012-08-20 06:36:32 +02:00
cd to NGINX source directory & run this:
2013-05-07 18:47:12 +02:00
./configure --add-module=<path-to-nginx-rtmp-module>
2012-08-20 06:36:32 +02:00
make
make install
2013-06-14 13:29:28 +02:00
Several versions of nginx (1.3.14 - 1.5.0) require http_ssl_module to be
2013-05-07 18:47:12 +02:00
added as well:
./configure --add-module=<path-to-nginx-rtmp-module> --with-http_ssl_module
2013-06-13 15:22:17 +02:00
### Windows limitations
Windows support is limited. These features are not supported
2013-06-13 15:37:58 +02:00
* execs
* static pulls
* auto_push
2013-06-13 15:22:17 +02:00
2012-11-16 14:27:35 +01:00
### RTMP URL format
2012-08-20 06:36:32 +02:00
2012-08-20 06:38:49 +02:00
rtmp://rtmp.example.com/app[/name]
2012-08-20 06:36:32 +02:00
2012-08-20 06:38:49 +02:00
app - should match one of application {}
2012-08-20 06:36:32 +02:00
blocks in config
2012-08-20 06:40:23 +02:00
2012-08-20 06:38:49 +02:00
name - interpreted by each application
2012-08-20 06:36:32 +02:00
can be empty
2012-08-30 15:57:00 +02:00
### Multi-worker live streaming
Module supports multi-worker live
streaming through automatic stream pushing
to nginx workers. This option is toggled with
rtmp_auto_push directive.
2012-11-16 14:27:35 +01:00
### Example nginx.conf
2012-08-20 06:36:32 +02:00
rtmp {
server {
listen 1935;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application mytv {
# enable live streaming
live on;
# record first 1K of stream
record all;
record_path /tmp/av;
record_max_size 1K;
# append current timestamp to each flv
record_unique on;
# publish only from localhost
allow publish 127.0.0.1;
deny publish all;
#allow play all;
}
# Transcoding (ffmpeg needed)
application big {
live on;
# On every pusblished stream run this command (ffmpeg)
# with substitutions: $app/${app}, $name/${name} for application & stream name.
#
# This ffmpeg call receives stream from this application &
# reduces the resolution down to 32x32. The stream is the published to
# 'small' application (see below) under the same name.
#
# ffmpeg can do anything with the stream like video/audio
# transcoding, resizing, altering container/codec params etc
#
# Multiple exec lines can be specified.
2013-02-06 09:58:04 +01:00
exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32x32 -f flv rtmp://localhost:1935/small/${name};
2012-08-20 06:36:32 +02:00
}
application small {
live on;
# Video with reduced resolution comes here from ffmpeg
}
2013-02-06 09:58:04 +01:00
application webcam {
live on;
# Stream from local webcam
exec_static ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://localhost:1935/webcam/mystream;
}
2012-08-20 06:36:32 +02:00
application mypush {
live on;
# Every stream published here
2013-11-30 08:21:53 +01:00
# is automatically pushed to
2012-08-20 06:36:32 +02:00
# these two machines
push rtmp1.example.com;
push rtmp2.example.com:1934;
}
application mypull {
live on;
# Pull all streams from remote machine
# and play locally
pull rtmp://rtmp3.example.com pageUrl=www.example.com/index.html;
}
2013-11-30 08:21:53 +01:00
2013-02-06 09:58:04 +01:00
application mystaticpull {
live on;
# Static pull is started at nginx start
pull rtmp://rtmp4.example.com pageUrl=www.example.com/index.html name=mystream static;
}
2012-08-20 06:36:32 +02:00
# video on demand
application vod {
play /var/flvs;
}
2012-08-27 17:12:34 +02:00
application vod2 {
play /var/mp4s;
}
2012-08-20 06:36:32 +02:00
# Many publishers, many subscribers
# no checks, no recording
application videochat {
live on;
2013-11-30 08:21:53 +01:00
# The following notifications receive all
# the session variables as well as
2012-08-20 06:36:32 +02:00
# particular call arguments in HTTP POST
# request
# Make HTTP request & use HTTP retcode
# to decide whether to allow publishing
# from this connection or not
on_publish http://localhost:8080/publish;
# Same with playing
on_play http://localhost:8080/play;
# Publish/play end (repeats on disconnect)
on_done http://localhost:8080/done;
# All above mentioned notifications receive
2013-11-30 08:21:53 +01:00
# standard connect() arguments as well as
2012-08-20 06:36:32 +02:00
# play/publish ones. If any arguments are sent
# with GET-style syntax to play & publish
# these are also included.
# Example URL:
# rtmp://localhost/myapp/mystream?a=b&c=d
# record 10 video keyframes (no audio) every 2 minutes
record keyframes;
record_path /tmp/vc;
record_max_frames 10;
record_interval 2m;
# Async notify about an flv recorded
on_record_done http://localhost:8080/record_done;
}
2012-09-25 07:05:06 +02:00
# HLS
2012-08-20 06:36:32 +02:00
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
2013-06-14 13:11:45 +02:00
# Incoming stream must be in H264/AAC. For iPhones use baseline H264
2012-08-20 06:36:32 +02:00
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
2013-11-30 08:21:53 +01:00
# ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264
# -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
2012-08-20 06:36:32 +02:00
# -f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use 'exec' feature.
#
application hls {
2012-12-14 07:13:15 +01:00
live on;
2012-08-20 06:36:32 +02:00
hls on;
hls_path /tmp/app;
hls_fragment 5s;
}
}
}
2012-08-20 06:38:49 +02:00
# HTTP can be used for accessing RTMP stats
2012-08-20 06:36:32 +02:00
http {
server {
listen 8080;
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
# Use this stylesheet to view XML as web page
# in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root /path/to/stat.xsl/;
}
location /hls {
# Serve HLS fragments
2013-02-06 09:58:04 +01:00
types {
application/vnd.apple.mpegurl m3u8;
2013-04-19 18:56:50 +02:00
video/mp2t ts;
2013-02-06 09:58:04 +01:00
}
2012-08-20 06:36:32 +02:00
alias /tmp/app;
2013-02-06 09:58:04 +01:00
expires -1;
2012-08-20 06:36:32 +02:00
}
}
}
2012-08-30 15:57:00 +02:00
2012-11-16 14:27:35 +01:00
### Multi-worker streaming example
2012-08-30 15:57:00 +02:00
rtmp_auto_push on;
rtmp {
server {
listen 1935;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application mytv {
live on;
}
}
}