Using Nginx to build streaming media live platform

Source: Internet
Author: User

All you have to say

The purpose of using Nginx to build streaming media platform is to support the RTMP protocol, which enables users to use RTMP (RTMP://192.168.201.128/MYAPP) protocol to push streaming to the server. The other user then requests the video stream information that the user pushes. Since it is the RTMP protocol, so you can use Adobe's Flashmedialiveencoder program, but also can be more professional streaming master software to complete the front-end live collection and coding. The individual is more like the use of streaming master, because this software is currently the most professional front-end coding system. To be honest, I'm actually a flash and flex developer, developing a variety of web video programs and video conferencing systems. The Java level is also very high. Welcome to face, I am such a person is not how humble, because I feel too humble hypocrisy. There are many streaming media servers around the world. There are commercial and open source, such as commonly used fms,red5,wowza.crtmpserver, and so on, if it is to do small video conferencing, I personally strongly recommend Red5. Red5 has a very open API, for the development of real-time requirements is relatively high convenience. Developers who develop tools and Java are also quick to get started.

Two environmental preparations

1 Prepare a Linux operating system, my Centos5. Windows is nignx to compile the module on its own, so I tested it on CentOS. My system information is as follows:

Linux localhost 2.6.18-128.el5 #1 SMP Wed 10:44:23 EST 2009 i686 Athlon i386 Gnu/linux

2 Preparing Packages

Nginx-1.4.7.tar.gz

Nginx-rtmp-module-1.1.7.tar.gz

Three Start installation

1 The dependency pack required to install the Nginx. Note that the dependencies of different systems or modules are not the same. I am here to install the most basic on the line.


[Root@localhost html]# yum install-y gcc gcc-c++

[Root@localhost html]# yum install–y openssl-devel pcre-devel

Note: It is best not to use the default Yum source. are uniformly replaced by Aliyun yum sources.

2 Unpack the bag first, it's no difficulty. Then execute the NINGX configuration file. After execution is done, compile, install


[Root@localhost local]# tar-zvxf nginx-1.4.7.tar.gz

[Root@localhost local]# wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.7.tar.gz

[Root@localhost local]# Tar nginx-rtmp-module-1.1.7.tar.gz

[Root@localhost local]# TAR-ZXVF nginx-rtmp-module-1.1.7.tar.gz

[Root@localhost local]# cd/usr/local/nginx-1.4.7

./configure--prefix=/usr/local/nginx--add-module=/usr/local/nginx-rtmp-module-1.1.7

[Root@localhost nginx-1.4.7]# make && make install


Output log I'm not going to post it. After the compilation is complete. To modify the Nginx configuration file, let Nginx support the RTMP protocol.

3 After modifying the configuration file, the contents are as follows (change the configuration file can refer to):

[Root@localhost test]# pwd
/usr/local/nginx-rtmp-module-1.1.7/test


[Root@localhost test]# LL

Total 56

-rwxrwxr-x 1 Root 2015 dump.sh

-rwxrwxr-x 1 Root 2015 ffstream.sh

-rw-rw-r--1 root root 1245 Mar 2015 nginx.conf

-rwxrwxr-x 1 Root 2015 play.sh

-rw-rw-r--1 root root 499 Mar 2015 readme.md

Drwxrwxr-x 2 root root 4096 Mar 2015 Rtmp-pu

For the convenience of me, I post my ngin profile completely:


#user nobody;

Worker_processes 1;

#error_log Logs/error.log;

#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;

#pid Logs/nginx.pid;

Events {

Worker_connections 1024;

}

rtmp {

server {

Listen 1935;

Application MyApp {

Live on;

#record keyframes;

#record_path/tmp;

#record_max_size 128K;

#record_interval 30s;

#record_suffix. this.is.flv;

#on_publish Http://localhost:8080/publish;

#on_play Http://localhost:8080/play;

#on_record_done Http://localhost:8080/record_done;

}

}

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

#access_log Logs/access.log Main;

Sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

Keepalive_timeout 65;

#gzip on;

server {

Listen 80;

server_name localhost;

Location/{

root HTML;

Index index.html index.htm;

}

#error_page 404/404.html;

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

}


Four boot servers, testing

1 perform Nginx/sbin/nginx start service. You should be able to see that the server also enables Port 1935, which means that Nginx has supported the rtmp push stream.


[Root@localhost conf]# Netstat-antpl

Active Internet connections (servers and established)

Proto recv-q Send-q Local address Foreign address State Pid/program Name

TCP 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN 11908/nginx

TCP 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2674/portmap

TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11908/nginx

TCP 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2965/cupsd

TCP 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2989/sendmail:acce

TCP 0 0 0.0.0.0:765 0.0.0.0:* LISTEN 2703/rpc.statd

TCP 0 0 192.168.201.128:1935 192.168.201.1:55561 established 11950/nginx:worker

TCP 0 1934 192.168.201.128:1935 192.168.201.1:55575 established 11950/nginx:worker

TCP 0 0:: £ º::* LISTEN 2950/sshd

TCP 0 0:: ffff:192.168.201.128:22:: ffff:192.168.201.1:56019 established 12197/sshd:root@no

TCP 0 592:: ffff:192.168.201.128:22:: ffff:192.168.201.1:53081 established 3268/1


2 Copy all the files in your/usr/local/nginx-rtmp-module-1.1.7/test/www directory under Nginx HTML. This is the test case provided by the RTMP module. is a flash Client push stream and a playback stream case; it looks as follows:


[Root@localhost www]# cd/usr/local/nginx/html/

[Root@localhost html]# LL

Total 60

-rw-r--r--1 root root 537 Feb 5 18:54 50x.html

-rw-r--r--1 root root 15145 Feb 5 19:05 bg.jpg

-rw-r--r--1 root root 511 Feb 5 19:06 index.html

Drwxr-xr-x 2 root root 4096 Feb 5 19:05 Jwplayer

Drwxr-xr-x 2 root root 4096 Feb 5 19:05 Jwplayer_old

-rw-r--r--1 root root 1460 Feb 5 19:07 record.html


Five Tests,

1 Open Browser Enter address: http://192.168.201.128/record.html This is the test address for a push stream. Opening will prompt you to allow the use of your webcam. Let's do it. As follows


2 open another browser, enter http://192.168.201.128/index.html this test playback address effect is as follows:


Six summary.

You can use OBS to publish to Nginx. In general this approach is good, but if you want real-time high, multiplayer video is not very applicable.

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.