http://blog.csdn.net/xdwyyan/article/details/43198985
主要步骤及命令记录:
1、下载nginx,地址http://nginx.org/en/download.html,选择最新版本下载、解压。当前最新版为:nginx-1.7.9。
2、为了增加对rtmp的支持,下载nginx-rtmp-module,地址:https://github.com/arut/nginx-rtmp-module#example-nginxconf,这个是个开源项目。解压后,为了和我在网上看到的教程同步,我改了文件夹名字,将其改成了nginx-rtmp-module。然后将其放到/home/user/目录下(今天才知道h和user非常像的目录usr是Unix System Resource的意思)。copy
cp -rf 123/nginx-rtmp-module/ /home/user/
./configure --prefix=/usr/local/nginx --add-module=/home/user/nginx-rtmp-module --with-http_ssl_module
- make
- make install
- gedit /usr/local/nginx/conf/nginx.conf
- #user nobody;
- worker_processes 1;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- rtmp {
- server {
- listen 1935;
- application myapp {
- live on;
- }
- application hls {
- live on;
- hls on;
- hls_path /tmp/hls;
- }
- }
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #gzip on;
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html;
- index index.html index.htm;
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- # HTTPS server
- #
- #server {
- # listen 443 ssl;
- # server_name localhost;
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
- # ssl_session_cache shared:SSL:1m;
- # ssl_session_timeout 5m;
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ssl_prefer_server_ciphers on;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- }
- /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] still could not bind()
- pkill -9 nginx
- <pre name="code" class="plain">netstat -tlnp|grep 1935
- tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN 20211/nginx.conf
- kill -9 20211
- Welcome to nginx!
- If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
- For online documentation and support please refer to nginx.org.
- Commercial support is available at nginx.com.
- Thank you for using nginx.
11、可以通过netstat -ltn 命令可以看到端口的监听情况.copy
- 激活Internet连接 (仅服务器)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN
- tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
- tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
- tcp6 0 0 ::1:631 :::* LISTEN
12、用ffmpeg推流到nginx,myapp上,我推送的是网络摄像机的rtsp直播视频流。用如下命令:copy
- ffmpeg -i rtsp://admin:12345@172.27.35.56 -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv rtmp://172.27.35.2:1935/myapp/test1
更正为:
ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 -f flv rtmp://127.0.0.1:1935/myapp/test1
来源于:https://trac.ffmpeg.org/wiki/Capture/Webcam
ffmpeg -loop 1 -pattern_type glob -i '350_frame/*.png' -c:v libx264 -t 600 -pix_fmt yuv420p -f flv rtmp://www.matchyun.com:1935/myapp/test1
上述命令参照http://www.tuicool.com/articles/eAfIVv具体参数还有待修改。
在VLC上打开网络串流 ,填写 rtmp://172.27.35.2:1935/myapp/test1可以看到监控画面,有大约2~3秒的延时。
sudo apt-get autoremove autoconf automake build-essential cmake libass-dev libfreetype6-dev \ libmp3lame-dev libopus-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev \ libvorbis-dev libvpx-dev libx264-dev libxcb1-dev libxcb-shm0-dev ibxcb-xfixes0-dev mercurial texinfo zlib1g-dev