直播系列4-使用nginx+nginx-rtmp-module+ffmpeg搭建流媒體伺服器筆記(一)
阿新 • • 發佈:2019-02-15
第一部分
主要步驟及命令記錄:
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的意思)。
- cp -rf 123/nginx-rtmp-module/ /home/user/
3、進入到nginx-1.7.9資料夾目錄下,執行如下命令:
- ./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; #檔案存放地址,這裡/tmp是和/usr評級的目錄
- }
- }
- }
- 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()
- kill -9 nginx
- 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 命令可以看到埠的監聽情況.
- 啟用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上,用如下命令:
-
ffmpeg -f dshow -i video="Integrated Webcam" -s 640x360 -vcodec libx264 -b:v 1000k -ab 128k -f flv rtmp://192.168.31.102:1935/myapp/test1
在VLC上開啟網路串流 ,填寫
rtmp://192.168.31.102:1935/myapp/test1可以看到監控畫面,有大約2~3秒的延時。
明天繼續,將流推送到hls上……