Build nginx-rtmp server under Windows

Source: Internet
Author: User
Tags xsl xsl file mercurial nginx server

Build nginx-rtmp server under Windows

    • Build nginx-rtmp server under Windows
      • Preparatory work
        • Installing MinGW
        • Installing mercurial
        • Installing Strawberryperl
        • Installing NASM
        • Download Nginx-related source code package
      • Compiling Nginx
      • NGINX-RTMP Environment Construction
      • Effect test
      • Final description

Recently, because of the technical work related to live broadcasting, using nginx based on high concurrency and high performance, the first thing to do is to build an Nginx server.
The construction of the Nginx server on Linux is not mentioned here, in accordance with the operation of the guidelines will generally be able to build up.
For the unskilled hand of Linux, of course, it is hoped to be able to use the same set under Windows. Just started in Windows to build the environment when encountered a lot of problems, after one by one to solve the cost of a lot of effort, afraid later forget, put me in Windows to build Nginx and set up rtmp Live server process recorded, right as a memo.

Preparatory work
  • Installing MinGW

    Before these preparations, there is at least one IDE installed on your computer, and mine is VS2008.
    First install the MinGW, the following Nginx compilation needs to be carried out in the Msys environment first.
    Installation method can be installed online and offline two ways, offline installation of the process is very cumbersome, you need to download a variety of package decompression, configuration path and so on, so the use of no-brain online installation instructions.
    Since many of the MinGW resources are downloaded in SourceForge, although the domestic can access, but the speed is very slow, the online installation process often occurs in the download component failure, it is highly recommended FQ installation.

    1. To MinGW find the link address of MinGW installation bootstrapper mingw-get-setup.exe and download, download the file less than 100KB. Execute the Installation tool and start selecting the installation path, and do not install the MinGW into a directory with spaces or Chinese paths!! .

    2. By default, after the download is complete, a MinGW installer shortcut icon is generated on the desktop, and if not, it can be found in the MinGW installation directory $MinGW安装目录\libexec\mingw-get\guimain.exe . Next run the shortcut icon after installation, select the components to be installed online, simply select the Msys and GCC related components in basic setup.
      Then, select Apply Changes in the installation menu to download and install online, the entire process may last for more than 10 minutes.
      Of course, there is a need to re-use this installation interface for component changes or deletions.

      If a component fails to download during the installation process, directly determine to continue down, the installer will be installed after all the dependencies are downloaded, after the completion of execution, without shutting down the installation interface, go back to the second step above and then again, until there is no installation error.

    3. At this point, after the successful installation of MinGW, the selected items will become light green filled.

      MinGW installation directory will also have Msys directory, into the directory, you will see a batch file msys.bat , you can create it to the desktop as a shortcut, double-click into the Msys environment. Using the same as the Linux terminal, but a lite version, the command is not full under Linux, you can use the Mingw-get command to install some packages online, for example, to install GDB, directly enter the command mingw-get install gdb .

      MinGW normally installed, the path is automatically added to the environment variable. If there is a problem in use, check whether the path $MinGW安装目录\bin environment variable is manually added to Windows because of the route settings $MinGW安装目录\msys\1.0\bin .

  • Installing mercurial

    Mercurial is a version management tool, we need to use it to download the Nginx source under Windows.

    1. Download the Windows version to mercurial and install it.

    2. It is best to select the installation directory under the path without spaces and Chinese directories. After the installation is complete, execute the command in CMD hg and the following display indicates that the installation was successful.

  • Installing Strawberryperl

    Strawberry Perl is the Perl environment of the Windows environment and contains everything you need to run and develop a Perl application, with the aim of being as close to the Perl environment as possible on UNIX systems, and later in compiling Nginx and its dependent libraries.

    1. To strawberry perl to download and install the installation program under Windows, it is best to select the installation path under the path without spaces and Chinese directories.
  • Installing NASM

    NASM full name of the Netwide assembler, is a 80x86 and x86-64 platform-based assembly language compiler, which was designed to achieve the compiler program cross-platform and modular features, as for why to install this goods, and later.

    1. Install the installer to nasm download.
    2. After the installation is complete, add its installation path to the PATH environment variable.
  • Download Nginx-related source code package

    Build nginx-rtmp server need to download Nginx source code and Nginx-rtmp-module source code. and Nginx-dependent components. The following will be configured under Msys, unlike Linux, which directly installs the dependent component header in the form of Yum install Xxx-devel. So it is necessary to download Nginx-related source packages, note that the source package, because Nginx compilation needs to reference these dependent library development header.

      • Nginx
        Linux under the Nginx source package can go directly to the Nginx website download, but the above source package only Linux, the source of the OS folder only UNIX platform. and Windows has only compiled files. Here you need to download the Nginx source package with the Win32 platform using mercurial.
        Execute commands in cmd hg clone nginx-win32-src download the latest Nginx code, patiently wait for the source down to local, you can also download the specified version, specific reference hg help .
      • Nginx-rtmp-module
        as an extension module for Nginx External, it will be used as part of the back-up rtmp live environment
        Use a tool like git or svn or go directly to GitHub to download Nginx-rtmp-module
      • Pcre
      • Zlib
      • Openssl

    Here are the versions of several source packages I use:
    nginx-release-1.31.1 tag

Compiling Nginx
  1. Copy the above downloaded five source packages to the Msys directory $MinGW安装目录\msys\1.0\home\$USERNAME\ .

  2. Open the Msys batch file and unzip the previously downloaded source package.

  3. Enter the Nginx source directory. Create a new Configuration-nginx.bat file, the contents of which are as follows, the following will be a few dependencies added to the configuration code according to the actual situation fill different paths.  

    auto/configure--with-cc=cl--builddir=objs--prefix= \ 
    --conf-path=conf/nginx.conf-- Pid-path=logs/ \ 
    --http-log-path=logs/access.log--error-log-path=logs/error.log \ 
    -- Sbin-path=nginx.exe--http-client-body-temp-path=temp/client_body_temp \ 
    --http-proxy-temp-path=temp/ Proxy_temp \ 
    --http-fastcgi-temp-path=temp/fastcgi_temp \ 
    --with-cc-opt=-dfd_setsize=1024 \  
    --with-select_module \ 
    --with-debug \ 
    --with-http_ssl_module \ 
    --with-pcre=. /pcre-8.40--with-zlib=. /zlib-1.2.11--with-openssl=. /openssl-1.0.2l \ 
    --add-module=.. /nginx-rtmp-module-1.1.11 

  4. Executes the batch file at this point and waits a few seconds for information about the Nginx configuration to complete.  
    Here you will find a strange hint, auto/cc/msvc:line 117: [:: Integer Expression expected  , as long as the file   $nginx Source directory \auto\cc\msvc  , in   Echo + cl Version: $NGX _msvc_ver "   is preceded by a line   ngx_msvc_ver=15.00   and of course not modifying will not affect subsequent compilations. &NBSP
    If you want to disable optimizations if you need to specify subsequent compilations,  , cflags= "$CFLAGS-o2" is modified to   cflags= "$CFLAGS-od"  .  

    So far, Msys's mission is complete.

  5. Open the Visual Studio 2008 Command prompt, enter the Nginx source directory at the command prompt, execute nmake /f objs\MakeFile the command, you will find the compilation error.

    At this point, the previously installed NASM should be on the scene.
    Open the file $nginx源码目录\auto\lib\openssl\makefile.msvc and place the
    Revision changed to
    Then, remove the Out32 and TMP32 two temporary directories in the OpenSSL source directory, restart the visual Studio 2008 command prompt, and perform the previous fifth step again .

  6. After successful compilation, the following printing information will eventually be available, and the resulting Nginx.exe file can be seen in the OBJS directory of the Nginx source directory.

NGINX-RTMP Environment Construction
    1. You can / create a new Nginx directory under the root directory of the Msys. The Conf directory under the generated Nginx.exe,nginx source directory and the HTML directory under the Docs directory are then copied to the current directory, and a new logs and temp two directories are created manually to form the final directory structure.

    2. Then modify the conf/nginx.conf, about how to configure and modify not within the scope of this article, so, skip ~.
      In the current Nginx directory, start the Windows command line and run the start /b nginx.exe -c conf\nginx.conf nginx service in the background. Enter the address in the browser into the Nginx service home page, if you can see the following, indicating that the entire environment is OK, then you can use push and pull flow to see the actual effect. Finally, use the command nginx.exe -s stop to gracefully terminate the Nginx service.

Effect test

The next effect test, a little bit of a change to the environment, using the Jwplayer play page provided in Nginx-rtmp-module to pull the stream or record page to push.

  1. The first is to create a new folder under the nginx/html/directory Nginx-rtmp-module, Copy the stat.xsl file and the test folder under the previously extracted nginx-rtmp-module-1.1.11 directory to the newly created directory nginx-rtmp-module.

  2. Modify nginx/html/nginx-rtmp-module/test/ nginx.conf file, close Nginx daemon and Master-worker mode, because this machine has SVN occupy 80 port, so modify HTTP service port is 8080, while the Nginx service access directory is modified to the index of the Nginx-rtmp-module point File. Then add the rtmp module configuration, the final configuration file content is as follows:

    worker_processes 1;daemon off; Master_process Off;error_log logs/error.log info;events {worker_connections 1024;}        rtmp {server {listen 1935;        Application Live {live on;        }}}http {server {listen 8080;            Location/stat {Rtmp_stat all;        Rtmp_stat_stylesheet stat.xsl;        } location/stat.xsl {root html/nginx-rtmp-module/;        } location/control {Rtmp_control all;        } location/rtmp-publisher {root html/nginx-rtmp-module/test;        } location/{root html/nginx-rtmp-module/test/www; }}}  
  3. Configure the pull-stream name, modify the nginx/html/nginx-rtmp-module/test/www/index.html file, and
    file: "rtmp://localhost/myapp?carg=1/mystream?sarg=2"Revision changed to
    file: "rtmp://localhost/live?carg=1/test?sarg=2"To remain consistent with the above configuration file.

  4. Configure the push stream name, modify the nginx/html/nginx-rtmp-module/test/www/record.html file, and start the
    ‘streamer‘: ‘rtmp://localhost/myapp‘,Revision changed to
    ‘streamer‘: ‘rtmp://localhost/live‘To remain consistent with the above configuration file.

  5. Enter Nginx directory under Msys, the execution nginx.exe -c html/nginx-rtmp-module/test/nginx.conf & Nginx service will run in the background.

  6. There are many ways to push the stream and push the stream, using FFmpeg to stream the local files and push them to the Nginx service.
    ffmpeg -re -i "F:\TDDownload\BBC记录片\BBC理查德哈蒙德:看不见的世界BD中字-cd1.mkv" -vcodec copy -f flv rtmp://

  7. Pull the stream, pull a lot of ways, browser open nginx Service Main Page, you can see the Video playback window appears, click Play to pull the stream, at this time the flow address is configured above rtmp:// , but also in the SRS player page
    The input stream address rtmp:// pulls the stream and can also take advantage of the ffplay rtmp:// pull stream.

  8. Open the Statistics page of the Nginx service can also see the current service running status.

  9. Using the Jwplayer record page to capture the camera and the data of the Mac pushes the stream to the Nginx service, pull the stream on the SRS player page, because the first configured record page of the push stream name is MyStream, so enter here rtmp:// .

Final description

Originally tried to try to play on the mobile side effect, but Jwplayer seems to be not supported directly on the HTML page rtmp live, but you can download an app (easy to push streaming) for rtmp live test.

About NGINX-RTMP Server build process to this even complete, in the process of course not all rely on my own groping, but also refer to the experience of predecessors or peers, here to thank those who have contributed, reference is as follows:

Build nginx-rtmp server 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: 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.