Build Nginx-based video live and on-demand systems under Windows

Source: Internet
Author: User
Tags xsl

First, software preparation

Because Nginx native is for Linux services, so the official version of Windows is not compiled can be downloaded, to use Nginx on Windows, either download the source code to compile, or use other people have compiled the file.

and to let Nginx support video live and on-demand, but also need a third-party Nginx module: nginx-rtmp-module

Fortunately, the great God has done the Nginx compiler, and integrated a lot of Nginx module, which has included the nginx-rtmp-module.

: http://nginx-win.ecsds.eu/, detailed description can be found in: Readme Nginx-win version.txt

I downloaded this version of Nginx 1.7.11.3 Gryphon.

This site also provides vcredist download (x86,x64) to avoid the lack of library errors when running Nginx.

Also download stat.xsl to display the current NGIX-RTMP service status

Also need to download FFmpeg, Ffplay, Yamdi:

Summarized as follows:

1. Nginx 1.7.11.3 Gryphon

2. stat.xsl

3. FFmpeg, Ffplay

4. Yamdi

Second, Nginx configuration

1. Nginx Configuration

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 {  # Enable recording                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/;        }     }}

Third, testing

1. Start Nginx

Start Nginx_1.7.11.3_gryphon\nginx

2. Push rtmp stream to 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 Live

Ffmpeg\ffplay "Rtmp://127.0.0.1:1935/hls/mystream"

4. HLS Live

Ffmpeg\ffplay "Http://127.0.0.1:18080/hls/mystream.m3u8"

5. Start recording

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

6. Stop Recording

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

7. Add an index to the rtmp-on-demand file or the progress bar cannot be dragged while the file is playing, assuming that the file you just recorded is named 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 on Demand

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

9. Making HLS on-demand shard file

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 E:\video-nginx\nginx_1.7.11.3_Gryphon\ Nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec-%d.ts

HLS on-demand

Ffplay "Http://127.0.0.1:8080/vod/mystream-1428384476_rec/mystream-1428384476_rec.m3u8"


Original link: http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/

Build Nginx-based video live and on-demand systems under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.