基于nginx和ffmpeg简单的直播环境搭建(rtmp+http-flv+hls)演示

网上很多文章都是介绍nginx的源码编译,但是首先我得看到效果啊,所以写下这篇文章:

话不多说,直接上效果图:

附上demo下载地址: https://download.csdn.net/download/xjb2006/12512911

1、解压到目录,比如D:\nginx
2、运行服务器软件:
     双击start.bat,任务管理器里面有2个nginx.exe就对了。

3、运行推送:
     打开ffmpeg下的推送桌面.bat,成功的话360显示ffmpeg.exe直接有流量了,nginx.exe也有流量了

4、本地打开浏览器或者客户端:(VLC或播放器)
     rtmp:  VLC或者打开rtmp播放器,输入地址.(浏览器不支持苹果)
     http-flv:VLC或者打开rtmp播放器,输入地址.(浏览器不支持苹果)
     HLS:苹果浏览器打开m3u8地址


5、说明:
     推送地址rtmp://127.0.0.1:1935/live/xiao
     接收端地址:
     本地rtmp 接收:    rtmp://127.0.0.1:1935/live/xiao
     本地http-flv 接收:    http://127.0.0.1:8002/live?app=live&port=1935&stream=xiao
     本地HLS 接收:          http://127.0.0.1:8002/hls/xiao.m3u8

     conf\nginx.conf可以修改配置 
     比较关键的值:
     rtmp:1935代表端口号
     application live:代表地址里面的live
     gop_cache off;关闭可以减少延迟           

     hls_playlist_length 4s; HLS设置
     hls_fragment 1s;#一个ts 文件的时长1s

 conf\nginx.conf配置文件:

worker_processes  1;
events {
    worker_connections  10240;
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp{#相当于数据输入
    out_queue 4096;
    out_cork 8;
    max_streams 128;
    timeout 15s;
    drop_idle_publisher 15s;
    log_interval 5s;
    log_size 1m;
    server{
     listen 1935; 
     application live{
         live on;
         gop_cache off;
      }
     application hls{
             hls_playlist_length 4s; 
              hls_fragment 1s;#一个ts 文件的时长1s
      live on;
      hls on;
      hls_path html/hls; 
    

    }
     application dash{
       live on;
       dash on;
       dash_path html/dash;
     }
    
    }
}
http {#相当于数据输出
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8002;
        server_name  127.0.0.1;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /live{
            flv_live on;
            chunked_transfer_encoding  on;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
        }
        location /hls{
            types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
             }
             root html;
             add_header 'Cache-Control' 'no-cache';
        }
        
         location /dash {
                root html/dash;
                add_header 'Cache-Control' 'no-cache';
        }
        
        location /stat {
                #configuration of push & pull status
                  rtmp_stat all;
                  rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
          root /usr/local/nginx/nginx-http-flv-module;
        }

        location /control {
                rtmp_control all; #configuration of control module of rtmp
        }    
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       8003;
        server_name  127.0.0.1;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

OK!完了。附上demo下载地址: https://download.csdn.net/download/xjb2006/12512911

猜你喜欢

转载自blog.csdn.net/xjb2006/article/details/106681078