国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

[多媒體服務(wù)器] 通過nginx搭建 rtmp/hls/dash 媒體服務(wù)器,支持點(diǎn)播和直播

這篇具有很好參考價(jià)值的文章主要介紹了[多媒體服務(wù)器] 通過nginx搭建 rtmp/hls/dash 媒體服務(wù)器,支持點(diǎn)播和直播。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

參考:

How To Set Up a Video Streaming Server using Nginx-RTMP on Ubuntu 20.04 | DigitalOcean




用到的工具:

nginx,nginx rtmp插件,OBS,ffmpeg,ubuntu,youtube-dl




Step1:安裝和配置nginx

安裝 nginx 和 rtmp 模塊

sudo apt install nginx
sudo apt update
sudo apt install libnginx-mod-rtmp

增加如下內(nèi)容到nginx配置文件 nginx.conf

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                allow publish 127.0.0.1;
                deny publish all;

                application live {
                        live on;
                        record off;
                }
        }
}

說明:

  • listen 1935?means that RTMP will be listening for connections on port 1935, which is standard.
  • chunk_size 4096?means that RTMP will be sending data in 4KB blocks, which is also standard.
  • allow publish 127.0.0.1?and?deny publish all?mean that the server will only allow video to be published from the same server, to avoid any other users pushing their own streams.
  • application live?defines an application block that will be available at the?/live?URL path.
  • live on?enables live mode so that multiple users can connect to your stream concurrently, a baseline assumption of video streaming.
  • record off?disables Nginx-RTMP’s recording functionality, so that all streams are not separately saved to disk by default.

打開1935端口的防火墻限制

sudo ufw allow 1935/tcp

nginx重新加載配置文件nginx.conf

sudo systemctl reload nginx.service



Step2:靜態(tài)流點(diǎn)播場景,通過hls或dash將MP4之類的多媒體封裝文件轉(zhuǎn)換為m3u8進(jìn)行點(diǎn)播

通過ffmpeg把MP4文件轉(zhuǎn)換為m3u8列表集:

ffmpeg -i input.mp4 -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -hls_wrap 10 output.m3u8

參數(shù)解釋:

  • -i input.mp4: 輸入文件

  • -codec: copy: 復(fù)制編解碼器

  • -start_number 0: 分片從0開始編號(hào)

  • -hls_time 10: 每個(gè)分片的時(shí)長為10秒

  • -hls_list_size 0: 播放列表不限制大小

  • -hls_wrap 10: 當(dāng)達(dá)到指定的段數(shù)時(shí),重新開始

  • output.m3u8: 輸出的播放列表文件

配置nginx以支持HLS,打開/etc/nginx/nginx.conf,添加如下內(nèi)容:

http {
    ...
 
    server {
        listen 80;
        server_name localhost.com;
 
        location /hls/ {
            # 假設(shè)m3u8和TS文件存儲(chǔ)在/home/yk/VOD/hls/1/目錄下
            root /home/yk/VOD/hls/1/;
            # 添加跨域配置(如果需要)
            add_header 'Access-Control-Allow-Origin' '*' always;
            # 添加HLS所需的MIME類型
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            # 禁止瀏覽目錄
            autoindex off;
        }
    }
}

nginx重新加載配置:

sudo nginx -s reload

瀏覽器中訪問:

?比如 ffmpeg 輸出的 ts 文件集 和 m3u8 列表在 /home/yk/VOD/1/ 目錄下,那么在瀏覽器中輸入

http://localhost.com:80/output.m3u8




Step3: 靜態(tài)流直播場景,把媒體文件推送給nginx rtmp服務(wù)進(jìn)行代理(rtmp不支持瀏覽器播放,只能通過vlc等播放器播放)

安裝ffmpeg

sudo apt install ffmpeg

安裝youtube-dl

sudo pip install youtube-dl

(可選)從youtube上下載一個(gè)文件備用,也可以隨便找一個(gè)MP4文件

youtube-dl https://www.youtube.com/watch?v=iom_nhYQIYk

使用ffmpeg處理媒體文件,并將其代理給rtmp服務(wù)器

ffmpeg -re -i "Introducing App Platform by DigitalOcean-iom_nhYQIYk.mkv" -c:v copy -c:a aac -ar 44100 -ac 1 -f flv rtmp://localhost/live/stream

?rtmp://localhost/live/stream 中的 localhost 代表本機(jī),不用動(dòng),live是nginx.conf文件里的 application live,如果是 application live1,那么這里就是 live1 , stream 是當(dāng)前流的標(biāo)識(shí),可以自定義為任何字符串。

Note:?You can also stream directly to, for example, Facebook Live using?ffmpeg?without needing to use Nginx-RTMP at all by replacing?rtmp://localhost/live/stream?in your?ffmpeg?command with?rtmps://live-api-s.facebook.com:443/rtmp/your-facebook-stream-key. YouTube uses URLs like?rtmp://a.rtmp.youtube.com/live2. Other streaming providers that can consume RTMP streams should behave similarly.




Step4:靜態(tài)流直播場景,支持hls和dash,以便通過瀏覽器播放

瀏覽器目前都不支持rtmp協(xié)議播放流媒體,如果希望通過瀏覽器播放,那么需要打開hls和dash協(xié)議支持。

打開 nginx.conf 文件,添加如下內(nèi)容:

. . .
rtmp {
        server {
. . .
                application live {
                    	live on;
                    	record off;
                        hls on;
                        hls_path /var/www/html/stream/hls;
                        hls_fragment 3;
                        hls_playlist_length 60;

                        dash on;
                        dash_path /var/www/html/stream/dash;
                }
        }
}
. . .

打開 sites-available/rtmp ,添加如下內(nèi)容:

. . .
server {
    listen 8088;

    location / {
        add_header Access-Control-Allow-Origin *;
        root /var/www/html/stream;
    }
}

types {
    application/dash+xml mpd;
}

放開8088端口的防火墻:

sudo ufw allow 8088/tcp

創(chuàng)建臨時(shí)媒體文件存放路徑給nginx用(參考上面的nginx.conf里的配置):

sudo mkdir /var/www/html/stream

重啟nginx:

sudo systemctl reload nginx

瀏覽器上訪問如下地址即可播放hls和dash

http://your_domain:8088/hls/stream.m3u8

http://your_domain:8088/dash/stream.mpd




Step5:管理rtmp資源(可選,數(shù)據(jù)統(tǒng)計(jì)頁面)

經(jīng)過step2以后,我們便可以通過支持rtmp協(xié)議的播放器進(jìn)行點(diǎn)播了。接著,需要開啟RTMP的統(tǒng)計(jì)頁面,這樣就不需要不斷地往nginx.conf文件里加配置來實(shí)現(xiàn)rtmp功能。我們可以創(chuàng)建一個(gè)配置文件:

/etc/nginx/sites-available/rtmp

把如下內(nèi)容放入這個(gè)文件里:

server {
    listen 8080;
    server_name  localhost;

    # rtmp stat
    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;
    }
    location /stat.xsl {
        root /var/www/html/rtmp;
    }

    # rtmp control
    location /control {
        rtmp_control all;
    }
}

?接著創(chuàng)建目錄:

/var/www/html/rtmp

然后通過如下命令把 libnginx-mod-rtmp的xsl配置文件解壓到上述目錄中:

sudo gunzip -c /usr/share/doc/libnginx-mod-rtmp/examples/stat.xsl.gz > /var/www/html/rtmp/stat.xsl

打開訪問統(tǒng)計(jì)數(shù)據(jù)頁面的防火墻:

sudo ufw allow from your_ip_address to any port http-alt

創(chuàng)建軟連接(這步是慣例,可以不做,具體原因后續(xù)補(bǔ)充):

sudo ln -s /etc/nginx/sites-available/rtmp /etc/nginx/sites-enabled/rtmp

重新加載nginx配置

sudo systemctl reload nginx.service

至此,統(tǒng)計(jì)頁面可以通過如下方式訪問

http://your_domain:8080/stat?

You’ve now seen how to monitor your video stream and push it to third party providers. In the final section, you’ll learn how to provide it directly in a browser without the use of third party streaming platforms or standalone media player apps.




Step6:動(dòng)態(tài)流直播場景,使用OBS進(jìn)行直播流代理

ffmpeg只能處理點(diǎn)播場景,直播場景需要使用OBS進(jìn)行流代理。

安裝OBS,check?Open Broadcaster Software | OBS

Streaming via?ffmpeg?is convenient when you have a prepared video that you want to play back, but live streaming can be much more dynamic. The most popular software for live streaming is?OBS, or Open Broadcaster Software – it is free, open source, and very powerful.

OBS is a desktop application, and will connect to your server from your local computer.

After installing OBS, configuring it means customizing which of your desktop windows and audio sources you want to add to your stream, and then adding credentials for a streaming service. This tutorial will not be covering your streaming configuration, as it is down to preference, and by default, you can have a working demo by just streaming your entire desktop. In order to set your streaming service credentials, open OBS’ settings menu, navigate to the?Stream?option and input the following options:

Streaming Service: Custom
Server: rtmp://your_domain/live
Play Path/Stream Key: obs_stream

obs_stream?is an arbitrarily chosen path – in this case, your video would be available at?rtmp://your_domain/live/obs_stream. You do not need to enable authentication, but you do need to add an additional entry to the IP whitelist that you configured in Step 1.

Back on the server, open Nginx’s main configuration file,?/etc/nginx/nginx.conf, and add an additional?allow publish?entry for your local IP address. If you don’t know your local IP address, it’s best to just go to a site like?What’s my IP?which can tell you where you accessed it from:

  1. sudo nano /etc/nginx/nginx.conf

Copy

/etc/nginx/nginx.conf

. . .
                allow publish 127.0.0.1;
                allow publish your_local_ip_address;
                deny publish all;
. . .

Save and close the file, then reload Nginx:

  1. sudo systemctl reload nginx.service

Copy

You should now be able to close OBS’ settings menu and click?Start Streaming?from the main interface! Try viewing your stream in a media player as before. Now that you’ve seen the fundamentals of streaming video in action, you can add a few other features to your server to make it more production-ready.文章來源地址http://www.zghlxwxcb.cn/news/detail-857362.html

到了這里,關(guān)于[多媒體服務(wù)器] 通過nginx搭建 rtmp/hls/dash 媒體服務(wù)器,支持點(diǎn)播和直播的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 多媒體API

    許小墨のBlog —— 菜雞博客直通車 系列文章完整版,配圖更多,CSDN博文圖片需要手動(dòng)上傳,因此文章配圖較少,看不懂的可以去菜雞博客參考一下配圖! 前端系列文章——傳送門 后端系列文章——傳送門 video 只接受幾種視屏格式:ogg、mp4、avi 基本使用: controls屬性,出現(xiàn)

    2024年02月02日
    瀏覽(29)
  • 多媒體音頻焦點(diǎn)淺析

    多個(gè)音源可以同時(shí)向同一個(gè)輸出流進(jìn)行播放音頻,如果沒有音頻焦點(diǎn)管控,就會(huì)出現(xiàn)多個(gè)音源同時(shí)播放的現(xiàn)象,給用戶帶來不便;而Android為了避免多個(gè)音源同時(shí)播放,就引入了音頻焦點(diǎn)的概念,所有音頻應(yīng)用都統(tǒng)一按照音頻焦點(diǎn)的規(guī)定執(zhí)行,就可以避免該現(xiàn)象發(fā)生。 當(dāng)應(yīng)用

    2024年02月13日
    瀏覽(36)
  • AIGC生成多媒體流程

    AIGC生成多媒體流程

    給定 生成多個(gè)故事標(biāo)題 多個(gè)故事標(biāo)題進(jìn)行反向推導(dǎo)出 再生成標(biāo)題 直到達(dá)到一個(gè)相似度 多個(gè)標(biāo)題固定總結(jié)合并為一個(gè)標(biāo)題 根據(jù)生成故事多個(gè)章節(jié)標(biāo)題 多個(gè)章節(jié)標(biāo)題反向生成一個(gè)標(biāo)題 對(duì)比前后兩個(gè)標(biāo)題相似度 不斷重復(fù)直到達(dá)到一定相似度 第一個(gè)章

    2024年02月12日
    瀏覽(94)
  • 多媒體開發(fā)之cgo

    多媒體開發(fā)之cgo

    ???? go語言作為近十年來優(yōu)秀的現(xiàn)代開發(fā)語言的代表,由于繼承了c語言的簡潔和很多現(xiàn)代語言的表達(dá)方式,在廣泛的應(yīng)用場景中得到眾多愛好者的喜愛,如何將go和c、c++進(jìn)行聯(lián)合開發(fā),拓展整個(gè)開發(fā)生態(tài),不用重復(fù)造輪子,掌握cgo可以讓你得心應(yīng)手的在c和go之間傳遞信息,

    2024年02月16日
    瀏覽(27)
  • 鴻蒙實(shí)戰(zhàn)多媒體運(yùn)用:【音頻組件】

    鴻蒙實(shí)戰(zhàn)多媒體運(yùn)用:【音頻組件】

    音頻組件用于實(shí)現(xiàn)音頻相關(guān)的功能,包括音頻播放,錄制,音量管理和設(shè)備管理。 圖 1 ?音頻組件架構(gòu)圖 基本概念 采樣 采樣是指將連續(xù)時(shí)域上的模擬信號(hào)按照一定的時(shí)間間隔采樣,獲取到離散時(shí)域上離散信號(hào)的過程。 采樣率 采樣率為每秒從連續(xù)信號(hào)中提取并組成離散信號(hào)

    2024年03月10日
    瀏覽(90)
  • 計(jì)算機(jī)網(wǎng)絡(luò)——多媒體網(wǎng)絡(luò)

    計(jì)算機(jī)網(wǎng)絡(luò)——多媒體網(wǎng)絡(luò)

    通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家, 跳轉(zhuǎn)到網(wǎng)站 我的計(jì)算機(jī)網(wǎng)絡(luò)專欄,是自己在計(jì)算機(jī)網(wǎng)絡(luò)學(xué)習(xí)過程中的學(xué)習(xí)筆記與心得,在參考相關(guān)教材,網(wǎng)絡(luò)搜素的前提下,結(jié)合自己過去一段時(shí)間筆記整理,而推出的該專欄,整體架構(gòu)是根據(jù)計(jì)算機(jī)網(wǎng)絡(luò) 自頂向下 方法而整理

    2024年02月20日
    瀏覽(21)
  • HTML5多媒體單元測試

    (單選題, 10.0分) 為元素指定多個(gè)視頻源使用( )標(biāo)簽(元素)。 A select B datalist C source D src (單選題, 10.0分) 判斷瀏覽器是否支持指定的媒體類型需用到audio或video對(duì)象的( )方法。 A load() B play() C pause() D canPlayType() (多選題, 10.0分) HTML5新增了強(qiáng)大的多媒體的功能,主要體現(xiàn)在

    2024年02月04日
    瀏覽(27)
  • Java UI組件和多媒體

    Java UI組件和多媒體

    目錄 1、使用單選按鈕 2、選擇幾何圖形 ?3、交通信號(hào)燈 ?4、演示TextField的屬性 5、演示TextArea的屬性 6、選擇一種字體 ?7、演示 Label 的屬性 ?8、使?用ComboBox 和 ListView? 9、使?用 ScrollBar 和 Slider ? ?10、模擬:一個(gè)轉(zhuǎn)動(dòng)的風(fēng)扇 編寫一個(gè) GUI 程序如圖所示 。 可以使用按鈕將消

    2024年02月09日
    瀏覽(25)
  • 多媒體工作中用到的小工具

    多媒體工作中用到的小工具

    安利下嵌入式多媒體用到的各種小工具 下面是同事們推薦的 以下是對(duì)這些軟件的簡要介紹: ocenaudio :ocenaudio是一款跨平臺(tái)的音頻編輯軟件,它提供了直觀的界面和豐富的功能,可以幫助用戶進(jìn)行音頻剪輯、修復(fù)、轉(zhuǎn)碼等操作。 MKVToolNix :MKVToolNix是一款開源的多媒體容器格

    2024年02月15日
    瀏覽(85)
  • 多媒體網(wǎng)絡(luò)教學(xué)模式的評(píng)價(jià)方式

    傳統(tǒng)教學(xué)評(píng)價(jià)只注重學(xué)生掌握的基本知識(shí),忽視其他各方面的技能,已經(jīng)不能 滿足多媒體網(wǎng)絡(luò)教學(xué)模式下的評(píng)價(jià)要求。建構(gòu)主義指導(dǎo)下的評(píng)價(jià)方式也應(yīng)遵循以學(xué) 習(xí)者為中心的原則,強(qiáng)調(diào)合作學(xué)習(xí),體現(xiàn)學(xué)習(xí)過程的重要性。因此,評(píng)價(jià)方式的多 元化必然會(huì)取代傳統(tǒng)單一的評(píng)價(jià)

    2024年02月11日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包