在Windows下搭建基於nginx的ApsaraVideo for Live和點播系統

來源:互聯網
上載者:User

標籤:pes   video   添加   time   profile   ext   eve   file   man   

一、軟體準備

由於nginx原生是為linux服務的,因此官方並沒有編譯好的windows版本可以下載,要在windows上使用nginx,要麼下載源碼進行編譯,要麼使用其他人已經編譯好的檔案。

而要讓nginx可使用視訊直播和點播,還需要第三方的nginx模組:nginx-rtmp-module

所幸,已經有大神做好了nginx的編譯,而且整合了很多nginx模組,其中就已經包括了nginx-rtmp-module。

:http://nginx-win.ecsds.eu/,詳細說明可參見:Readme nginx-win version.txt

我下載的是nginx 1.7.11.3 Gryphon這個版本。

這個網站同時也提供了vcredist的下載(x86,x64),以避免運行nginx時出現缺少庫的錯誤。

另外還要下載 stat.xsl 用於顯示當前ngix-rtmp服務狀態

另外還需要下載ffmpeg、ffplay、yamdi:

總結如下:

1. nginx 1.7.11.3 Gryphon

2. stat.xsl

3. ffmpeg、ffplay

4. yamdi

二、Nginx 配置

 1. nginx配置

worker_processes  1;error_log  logs/error.log debug;events {    worker_connections  1024;}rtmp {    server {        listen 1935;        application hls {             live on;  #啟用rtmp直播                       #地址為rtmp://[server]:[rtmp_port]/[app]/[stream]             hls on;   #啟用hls直播                       #地址為http://[server]:[http_port]/[app]/[stream].m3u8                       #需要配合下面http段設定使用             hls_path nginx-rtmp-module/tmp/app/;             hls_fragment 5s;             recorder rec {  #啟用錄製               record all manual;  #手動控制錄製啟停               record_suffix _rec.flv;               record_path nginx-rtmp-module/tmp/rec/;  #錄製儲存地址               record_unique on;           }       }       application vod2{  #rtmp點播       play nginx-rtmp-module/tmp/rec/;           }    }}http {    server {        listen      18080;        location /stat {  #伺服器狀態            rtmp_stat all;            rtmp_stat_stylesheet stat.xsl;        }        location /stat.xsl {            root nginx-rtmp-module/;        }        location /control { #控制器            rtmp_control all;        }        location /hls/ {  #hls直播地址           #server hls fragments           types{             application/vnd.apple.mpegurl m3u8;             video/mp2t ts;           }           alias nginx-rtmp-module/tmp/app/;           expires -1;        }        location /vod/{  #hls點播地址            alias nginx-rtmp-module/tmp/rec/;        }        location / {            root nginx-rtmp-module/test/www/;        }    }}

 

三、測試

1. 啟動nginx

start nginx_1.7.11.3_Gryphon\nginx

 

2. 推送rtmp流到nginx-rtmp

start ffmpeg\ffmpeg -re -i rtmp://live.hkstv.hk.lxdns.com/live/hks -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec copy -f flv rtmp://localhost:1935/hls/mystream -loglevel quiet

 

3. rtmp直播

ffmpeg\ffplay "rtmp://127.0.0.1:1935/hls/mystream"

 

4. hls 直播

ffmpeg\ffplay "http://127.0.0.1:18080/hls/mystream.m3u8"

 

5. 開始錄製

http://127.0.0.1:18080/control/record/start?app=hls&name=mystream&rec=rec

 

6. 停止錄製

http://127.0.0.1:18080/control/record/stop?app=hls&name=mystream&rec=rec

 

7. 為rtmp點播檔案添加索引,否則檔案在播放時進度條不能拖動,假定剛才錄製的檔案名稱為mystream-1428384476_rec.flv

yamdi\yamdi -i nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -o nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec_idx.flv

 

8. rtmp點播

ffmpeg\ffplay "rtmp://127.0.0.1:1935/vod2/mystream-1428384476_rec_idx.flv"

 

9. 製作hls點播分區檔案

ffmpeg\ffmpeg -i E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -acodec copy -bsf:a h264_mp4toannexb -g 105 -vcodec libx264 -vprofile baseline -bf 0 -bufsize 850k -bsf:v dump_extra -map 0 -f segment -segment_format mpegts -segment_list "E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec.m3u8" -segment_time 10 E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec-%d.ts

 

10. hls 點播

ffplay "http://127.0.0.1:8080/vod/mystream-1428384476_rec/mystream-1428384476_rec.m3u8"

在Windows下搭建基於nginx的ApsaraVideo for Live和點播系統

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.