部署RTMP(nginx)视频流服务

打印 上一主题 下一主题

主题 495|帖子 495|积分 1485

利用 Root 用户进行配置

: 切换 root 用户
  1.          sudo(superuser do或 switch user do,用于提权)
  2.          格式:sudo -u USERNAME COMMAND
复制代码
sudo -i
  1.          ​su​(switch user 或 substitute,用于切换用户)
  2.          格式:su -l USERNAME(-l为login,即登陆的简写)
  3.         -l 可以将l省略掉,所以此命令常写为su - USERNAME
  4.         三种方式切换到root的命令:su,su -和su - root
复制代码
     su -l       切换到 /etc 目次,创建并切换 rtmpServer 文件夹   
  1.         cd /etc
  2.         mkdir rtmpServer
  3.         chmod 777 rtmpServer  #(修改文件夹权限)
  4.     cd rtmpServer
复制代码
将nginx-rtmp-module和nginx下载到该文件夹下。

Nginx

Nginx HTTP服务器,是用于 Web 服务、反向署理、内容缓存、负载均衡、媒体传播输等场景的开源软件。 这个流媒体服务器
安装 Nginx 1.8.1

下载地址 Nginx
利用 wget 下载
wget http://nginx.org/download/nginx-1.8.1.tar.gz
解压 nginx
tar -zxvf nginx-1.8.1.tar.gz
安装nginx的依靠库(可能存在环境变量版本等题目)
  1.         sudo apt-get update
  2.         sudo apt-get install libpcre3 libpcre3-dev
  3.         sudo apt-get install openssl libssl-dev
复制代码
Nginx-rtmp-module

nginx-rtmp-module Nginx 一个nginx的流媒体服务器模块,可以支持RTMP和HLS(Live Http Stream)。
下载 nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module.git

配置并编译nginx

进入到nginx-1.8.1安装目次, 进入nginx源码目次,修改configure配置文件
添加nginx的rtmp模块。 add-module为下载的nginx-rtmp-module文件路径。
  1. cd nginx-1.8.1
  2. *[注释]:
  3.         修改配置
  4.                 ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=../nginx-rtmp-module
  5. *[注释]
  6.         默认配置
  7.                 ./configure --add-module=../nginx-rtmp-module
  8. make        # 环境版本 问题影响安装
  9. sudo make install
复制代码

运行测试nginx

进入安装目次/usr/local/nginx,运行下令./sbin/nginx
  1.         cd /usr/local/nginx
  2.         ./sbin/nginx
复制代码
打开欣赏器在地址栏输入:localhost。假如
配置 RTMP 视频点播

打开配置文件nginx.conf,添加RTMP的配置。
  1. worker_processes  1;
  2. events {
  3.    worker_connections  1024;
  4. }
  5. rtmp {                #RTMP服务 ** 添加即可 **
  6.    server {
  7.        listen 1935;  #//服务端口
  8.    chunk_size 4096;   #//数据传输块的大小
  9.    application vod {
  10.        play /opt/video/vod; #//视频文件存放位置。
  11.    }
  12.    }
  13. }
  14. http {
  15.    include       mime.types;
  16.    default_type  application/octet-stream;
  17.    sendfile        on;
  18.    keepalive_timeout  65;
  19.    server {
  20.        listen       80;
  21.        server_name  localhost;
  22.        location / {
  23.            root   html;
  24.            index  index.html index.htm;
  25.        }
  26.       
  27.        location /stat {    #第二处添加的location字段。
  28.             rtmp_stat all;
  29.             rtmp_stat_stylesheet stat.xsl;
  30.         }
  31.         location /stat.xsl { #第二处添加的location字段。
  32.             root /etc/rtmpServer/nginx-rtmp-module/;
  33.         }
  34.        error_page   500 502 503 504  /50x.html;
  35.        location = /50x.html {
  36.            root   html;
  37.        }
  38.    }
  39. }
复制代码
rtmp 欣赏器不能直接播放 可转为 hls/

  1. #user  nobody;
  2. worker_processes  1;
  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;
  6. #pid        logs/nginx.pid;
  7. events {
  8.     worker_connections  1024;
  9. }
  10. rtmp_auto_push off;
  11. rtmp_auto_push_reconnect 1s;
  12. rtmp_socket_dir /tmp;
  13. rtmp {                #RTMP服务
  14.     server {
  15.         listen 1935;  #//服务端口
  16.         drop_idle_publisher 30s; #// 缓存时长
  17.         chunk_size 4096;   #//数据传输块的大小
  18.                 application live { #创建一个叫live的应用
  19.              live on;#开启live的应用
  20.              allow publish 127.0.0.1;#
  21.              allow play all;
  22.              # exec_pull ffmpeg -i rtsp://admin:admin@10.10.10.11/axis-media/media.amp -threads 2 -f flv -r 25 -s 1280x720 -an rtmp://localhost:1935/cam1/stream 2>>/var/log/nginx/ffmpeg.log;
  23.             interleave off;
  24.             #exec_options on;
  25.             #exec_push ffmpeg -i rtmp://localhost/live/test -c copy -f flv rtmp://localhost/live/test;
  26.             hls on; #开启hls
  27.             hls_path /etc/rtmpServer/nginx-1.8.1/html/hls;
  28.             #hls的ts切片存放路径
  29.             hls_fragment 2s;
  30.             #本地切片长度
  31.             hls_playlist_length 6s;
  32.         }
  33.         application hls {
  34.             live on;
  35.             hls off;
  36.             #gop_cache off;
  37.             #gop_max_frame_count 256;
  38.             #gop_max_video_count 128;
  39.             #gop_max_audio_count 128;
  40.             #wait_key on;
  41.             #hls_path www/hls;
  42.             #hls_fragment 2s;
  43.             #hls_playlist_length 10s;
  44.         }
  45.         application vod {
  46.             play /opt/video/vod; #//视频文件存放位置。
  47.         }
  48.        
  49.     }
  50. }
  51. http {
  52.     include       mime.types;
  53.     default_type  application/octet-stream;
  54.     #flv_live on;
  55.     chunked_transfer_encoding on;
  56.     add_header Cache-Control no-cache;
  57.     add_header Access-Control-Allow-Origin * always;
  58.     add_header Access-Control-Allow-Headers X-Requested-With;
  59.     add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
  60.     access_log off;
  61.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  62.     #                  '$status $body_bytes_sent "$http_referer" '
  63.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  64.     #access_log  logs/access.log  main;
  65.     sendfile        on;
  66.     #tcp_nopush     on;
  67.     #keepalive_timeout  0;
  68.     keepalive_timeout  65;
  69.     #gzip  on;
  70.     server {
  71.         listen       80;
  72.         server_name  localhost;
  73.         #charset koi8-r;
  74.         #access_log  logs/host.access.log  main;
  75.         location / {
  76.             root   html;
  77.             index  index.html index.htm;
  78.             
  79.             add_header Access-Control-Allow-Origin '*' always;
  80.             add_header Access-Control-Allow-Headers '*';
  81.             add_header Access-Control-Allow-Methods '*';
  82.             add_header Access-Control-Allow-Credentials 'true';
  83.         }
  84.         location /stat {    #第二处添加的location字段。
  85.             rtmp_stat all;
  86.             rtmp_stat_stylesheet stat.xsl;
  87.         }
  88.         location /stat.xsl { #第二处添加的location字段。
  89.             root /etc/rtmpServer/nginx-rtmp-module/;
  90.         }
  91.         #配置hls点播
  92.         location /hls {
  93.             types {
  94.                 application/vnd.apple.mpegurl m3u8;
  95.                 video/mp2t ts;
  96.             }
  97.             alias /etc/rtmpServer/nginx-1.8.1/html/hls;
  98.             add_header Cache-Control no-cache;
  99.             add_header 'Access-Control-Allow-Origin' '*' always;
  100.             add_header 'Access-Control-Allow-Credentials' '*';
  101.             add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS';
  102.             add_header 'Access-Control-Expose-Headers' 'Server,range,Content-Length,Content-Range';
  103.         }
  104.         #error_page  404              /404.html;
  105.         # redirect server error pages to the static page /50x.html
  106.         #
  107.         error_page   500 502 503 504  /50x.html;
  108.         location = /50x.html {
  109.             root   html;
  110.         }
  111.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  112.         #
  113.         #location ~ \.php$ {
  114.         #    proxy_pass   http://127.0.0.1;
  115.         #}
  116.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  117.         #
  118.         #location ~ \.php$ {
  119.         #    root           html;
  120.         #    fastcgi_pass   127.0.0.1:9000;
  121.         #    fastcgi_index  index.php;
  122.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  123.         #    include        fastcgi_params;
  124.         #}
  125.         # deny access to .htaccess files, if Apache's document root
  126.         # concurs with nginx's one
  127.         #
  128.         #location ~ /\.ht {
  129.         #    deny  all;
  130.         #}
  131.     }
  132.     # another virtual host using mix of IP-, name-, and port-based configuration
  133.     #
  134.     #server {
  135.     #    listen       8000;
  136.     #    listen       somename:8080;
  137.     #    server_name  somename  alias  another.alias;
  138.     #    location / {
  139.     #        root   html;
  140.     #        index  index.html index.htm;
  141.     #    }
  142.     #}
  143.     # HTTPS server
  144.     #
  145.     #server {
  146.     #    listen       443 ssl;
  147.     #    server_name  localhost;
  148.     #    ssl_certificate      cert.pem;
  149.     #    ssl_certificate_key  cert.key;
  150.     #    ssl_session_cache    shared:SSL:1m;
  151.     #    ssl_session_timeout  5m;
  152.     #    ssl_ciphers  HIGH:!aNULL:!MD5;
  153.     #    ssl_prefer_server_ciphers  on;
  154.     #    location / {
  155.     #        root   html;
  156.     #        index  index.html index.htm;
  157.     #    }
  158.     #}
  159. }
复制代码
无人机连接 利用 rtmp 开启直播

无人机配置



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

梦见你的名字

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表