詳解如何基于Nginx搭建流媒體服務(wù)器
HLS是最常見的視頻流媒體協(xié)議,HLS是一種自適應(yīng)流媒體技術(shù),可以根據(jù)用戶的設(shè)備和網(wǎng)絡(luò)條件對(duì)播放媒體內(nèi)容,以獲得最佳播放性能。
Nginx RTMP是一個(gè)Nginx插件,支持將RTMP和HLS流添加到媒體服務(wù)器。以u(píng)buntu為力,下面介紹如何安裝使用nginx Rtmp 插件的步驟。

1.更新apt庫
apt-get update
2.安裝ffmpeg等所需要的軟件
apt-get install -y git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev
3.下載RTMP模塊
git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git
4.下載并解壓Nginx
wget http://nginx.org/download/nginx-1.17.6.tar.gztar -xf nginx-1.17.6.tar.gzcd nginx-1.17.6
5.配置Nginx
拷貝一份nginx配置文件出來
mv /usr/local/nginx/conf/nginx.confnano /usr/local/nginx/conf/nginx.conf
將以下內(nèi)容復(fù)制到nginx.conf文件中
worker_processes auto;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server
{
listen 1935;
# Listen on standard RTMP
portchunk_size 4000;
application show
{
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmpdeny
play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
# 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/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
}6.啟動(dòng)Nginx
/usr/local/nginx/sbin/nginx
7.測(cè)試
該服務(wù)器可以從各種來源進(jìn)行流式傳輸,包括靜態(tài)文件、網(wǎng)絡(luò)攝像頭等。由于上面的步驟中安裝了ffmpeg,我們可以將example-vid.mp4視頻文件流式傳輸?shù)絟ttp服務(wù)http://localhost/show/stream。
ffmpeg -re -i example-vid.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://localhost/show/stream
8.最后
根據(jù)服務(wù)的需求,可以將http服務(wù)集成到您的應(yīng)用程序或者網(wǎng)頁中。
到此這篇關(guān)于詳解如何基于Nginx搭建流媒體服務(wù)器的文章就介紹到這了,更多相關(guān)nginx搭建流媒體服務(wù)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在Nginx中配置image filter模塊來實(shí)現(xiàn)動(dòng)態(tài)生成縮略圖
這篇文章主要介紹了在Nginx中配置image filter模塊來實(shí)現(xiàn)動(dòng)態(tài)生成縮略圖的方法,包括縮略圖尺寸的設(shè)置等方面的介紹,需要的朋友可以參考下2015-12-12
云服務(wù)器使用寶塔搭建Python環(huán)境,運(yùn)行django程序
本文詳細(xì)講解了在云服務(wù)器使用寶塔搭建Python環(huán)境,運(yùn)行django程序的方法。對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-12-12
基于nginx獲取代理服務(wù)ip以及客戶端真實(shí)ip詳解
最近在研究nginx中如何獲取真實(shí)客戶端IP的方法,下面這篇文章主要給大家介紹了基于nginx獲取代理服務(wù)ip以及客戶端真實(shí)ip的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07
Nginx的偽靜態(tài)配置中使用rewrite來實(shí)現(xiàn)自動(dòng)補(bǔ)全的實(shí)例
這篇文章主要介紹了Nginx的偽靜態(tài)配置中使用rewrite來實(shí)現(xiàn)自動(dòng)補(bǔ)全的實(shí)例,文中對(duì)rewrite的相關(guān)參數(shù)和正則表達(dá)使用也做了介紹,需要的朋友可以參考下2015-12-12
解決nginx報(bào)錯(cuò)信息 client intended to send too large body: 1331696
這篇文章主要介紹了解決nginx報(bào)錯(cuò) client intended to send too large body: 1331696 bytes的相關(guān)資料,需要的朋友可以參考下2017-02-02

