java搭建直播平台_直播平台简单搭建笔记

本文详细介绍了如何使用Java搭建直播平台,涵盖了RTMP、HLS、HTTP-FLV等实时传输协议,并提供了从编译环境设置到nginx、nginx-rtmp-module的安装步骤,以及OBS Studio、ffmpeg的安装和配置。通过配置nginx.conf文件,实现了点播和直播功能,最后展示了使用ffmpeg进行视频流推流的命令。
摘要由CSDN通过智能技术生成

直播平台大致流程

4795c9322f5a72fb53d82f4656550180.png

实时传输协议有:RTMP、HLS、HDL(HTTP-FLV)

编译环境

apt-get install build-essential

nginx安装

安装pcre(目前最新8.44)

./configuremake && make installpcre-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 {

listen1935;#//服务端口

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 requestsif ($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

结果

f26e287605edf4f7dfe38a28f809ac1c.png

fb551d1aba22fa635599473b513479e7.png

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值