当前位置: 移动技术网 > IT编程>网页制作>CSS > 直播平台简单搭建笔记

直播平台简单搭建笔记

2020年03月30日  | 移动技术网IT编程  | 我要评论

直播平台大致流程

实时传输协议有:rtmp、hls、hdl(http-flv)

编译环境

apt-get install build-essential

 

nginx安装

 安装pcre(目前最新8.44)

./configure
make && make install

pcre-config --version //查看版本

下载nginx-rtmp-module

git 下载https://github.com/arut/nginx-rtmp-module

安装nginx(目前最新1.17.9)

./configure --add-module=../nginx-rtmp-module --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.44

make

make install

 

 

obs studio视频直播录制软件安装(debian尽量9以上,因为ops有要求,不然自己编译有点麻烦)

https://obsproject.com/download

 

ffmpeg转码安装

https://obsproject.com/wiki/install-instructions#linux里有安装流程

或者低版本的

sh -c 'echo "deb http://www.deb-multimedia.org jessie main" >> /etc/apt/sources.list'

apt-get update

apt-get install deb-multimedia-keyring

apt-get install ffmpeg

 

rtmp参数配置

nginx.conf点播配置

 
#播放地址示例: rtmp://localhost/live/qq.mp4 
rtmp { #rtmp服务
 server {
 listen 1935; #//服务端口
 chunk_size 4096; #//数据传输块的大小
 application live {
 play /usr/local/nginx/video; #//视频文件存放位置。
 }
}
}

 

 

 

 

nginx.conf直播配置

rtmp里

        application show {
            live on;
            #enable hls
            hls on;
            hls_path /usr/local/nginx/video/hls;
            hls_fragment 3;
            hls_playlist_length 20;
        }

http-server里

location /hls {
    # disable cache
    add_header cache-control no-cache;

    # cors setup
    add_header 'access-control-allow-origin' '*' always;
    add_header 'access-control-expose-headers' 'content-length';

    # allow cors preflight requests
    if ($request_method = 'options') {
        add_header 'access-control-allow-origin' '*';
        add_header 'access-control-max-age' 1728000;
        add_header 'content-type' 'text/plain charset=utf-8';
        add_header 'content-length' 0;
        return 204;
    }

    types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
    }

    root /usr/local/nginx/video/hls/;
    add_header cache-control no-cache;
}

重启nginx

sudo ./sbin/nginx -s reload

 

 

开启 ffmpeg

ffmpeg -re -i /usr/local/nginx/video/test.mp4 -vcodec libx264 -vprofile baseline -acodec aac -strict -2 -f flv rtmp://localhost/show/stream

 

结果

 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网