Crtmpserver Series (b): Set up a simple streaming media live system

Source: Internet
Author: User
Tags openssl library

Crtmpserver Introduction

In the first chapter we have briefly explained that Crtmpserver,crtmpserver is an open source rtmp streaming server written by the C + + language, and its corresponding commercial product is naturally an Adobe FMS. Compared with FMS, the function of Crtmpserver can only be called the simplified version of FMS, its function is no FMS so perfect or even far from reaching. Its compatibility with Flash Player is not as natural as the official FMS. However, Crtmpserver provides the most common rtmp implementations. As an open source high-performance rtmp streaming server, not only can be used on the x86 platform of the Linux server, Windows Server, but also can be used in arm and other embedded platforms. Crtmpserver code structure is good, class inheritance system is clear, code efficiency is high. is a good example of learning rtmp protocol and server-side programming.

Crtmpserver's official website is www.rtmpd.com but at present the site seems to be out of the question, and can not open, Crtmpserver Google Forum on the Netizen said crtmpserver the source temporarily moved to GitHub, The specific address is https://github.com/shiretu/crtmpserver if you want to download to the latest Crtmpserver source code, you can go to the git page download. Follow up on the official website of Crtmpserver, too.

This series of articles does not intend to use the code downloaded from this git, and since the Crtmpserver code used in previous work is based on the 717 version, the series will also be based on this version. Please download the crtmpserver-717.tar.gz code package here with the associated OpenSSL code openssl-1.0.1c.tar.gz

Compiling and running Crtmpserver under Linux

The release version of this Linux use is Ubuntu 10.10, with the following versions of each compiled tool:
GCC (Ubuntu/linaro 4.6.3-1ubuntu5) 4.6.3
g++ (Ubuntu/linaro 4.6.3-1ubuntu5) 4.6.3
CMake version 2.8.7

Crtmpserver source relies on OpenSSL, so we need to compile the OpenSSL library first and install the related header file. In addition, Crtmpserver uses the CMake tool for source code compilation management, so you also need to install CMake.

OpenSSL compile: This time use is openssl-1.0.1c.tar.gz decompression after the source root directory directly run:
$./config
$ make
$ make Test
$ make Install

Crtmpserver compilation: Unzip the download to the GZ compressed package, run the following command:
CD crtmpserver-717/builders/cmake/
CMake.
Make

Report the following error when make:

In the file tinyxmlparser.cpp there is a variable ptrdiff_t not defined, we open the file, in the No. 407 row variable ptrdiff_t plus std prefix can be changed to std::p trdiff_t, and then continue to make

The following error occurs after:

said that there is a variable objectencoding is not used after the definition, and the warning is treated as an error. We just need to modify the CMakeFileLists.txt to find the following line, comments out can be, in fact, the main thing is to remove the-WERROR option:

You will need to re-cmake this after modifying the CMakeFileLists.txt so that the makefile file is regenerated, then make until finished, and the information after the final completion is this:

Run Crtmpserver, after compiling the directory is still in the crtmpserver-717/builders/cmake/directory, run the following command directly:
./crtmpserver/crtmpserver./crtmpserver/crtmpserver.lua

After the program runs successfully, it displays as follows, indicating a successful run:

Under Windows compile and run Crtmpserver

First compiling crtmpserver under Windows also requires the Windows version of OpenSSL, so we need to compile the Windows version of OpenSSL first.

Compile the Windows version of OpenSSL: After extracting OpenSSL, there is a install.w32 or install.w64 with instructions on how to compile the Windows version of OpenSSL, and we take Win32 as an example.

To compile OpenSSL requires Perl support, we first install the Perl tool in the Windows environment, which is: Http://www.activestate.com/activeperl My computer is 64-bit, so I downloaded the Activeperl-5.24.0.2400-mswin32-x64-300558.exe install directly, select "Typical" in the next step of the installation.

After the installation is complete, we are ready to start compiling the Windows version of OpenSSL, as follows:

<1>. I'm using a VS2010. The other versions should not be much worse, open start---programs---Microsoft Visual Studio---Visual Studio Tools---Visual Studio command Prompt (2010), Note that here to open the command line of VS 2010 from the menu, will automatically set some environment variables, if run "start"---"Run"--cmd.exe this command line, may compile the time to find the header file, etc.
<2>. On the VS2010 command line that opens above, CD to the OpenSSL source root directory, and then run the following command:
Perl Configure Vc-win32 no-asm--prefix=c:/openssl-1.0.1c
Specify the configuration and set the installation directory for OpenSSL
<3>. Ms\do_ms
<4>. Add the path where the Nmake.exe is located to the system environment variable, for example I find Nmake.exe is under D:\Program Files\Microsoft Visual Studio 10.0\vc\bin
<5>. Add D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE to the environment variable, because cl.exe requires mspdb100.dll in this directory, otherwise it will return a 0x80 error. You should also look under the relevant installation directory of your own VS2010.
<6>. Nmake-f Ms\ntdll.mak
<7>. Nmake-f Ms\ntdll.mak Test This step is to compile the test, can not do, just to test whether the above is compiled
<8>. Nmake-f Ms\ntdll.mak Install this step is installed, will be installed into our 4th step in the specified--prefix=c:/openssl-1.0.1c directory, that is, copy the relevant library files here

The interface under Windows for OpenSSL compilation finishes is as follows:

The installation completed interface is as follows:

Now start compiling the Windows version of the Crtmpserver, open the Crtmpserver source directory of the Builders\vs2010\vs2010.sln project, directly above the solution right-click, build the solution. An error message appears that the OpenSSL header file could not be found:

The various modules of crtmpserver in VS2010 are individually made as project projects, and many projects have been used for OpenSSL, so we need to set the path of a global OpenSSL header file and library file. Setting the global inclusion in VS2010 is not as convenient as the VC, first open the Property Manager window:

Open the panel and select an item, expand the interface, double-click the specified project file, and specify the Include directory path in the popup interface:

Specify the path to the library file in the same way:

Continue compiling, found the following error:

In the two places shown, the value of 0 is changed to (uint32_t) 0; Continue compiling, report a link error, and have some IntelliSense errors, as follows:

In the VS2010.sln solution provided by the Crtmpserver official source code, there are two source files not added to the project, we add them manually, for example, open the Thelib project, expand the RTP directory, and right-click to add an existing project:

Select the header file nattraversalprotocol.h the file in the sources/thelib/include/protocols/rtp/directory of the source directory:

The same way to add CPP files, the CPP file is located in the directory of the sources/thelib/src/protocols/rtp/directory:

After the add is complete, the solution build succeeds, and we need to set the command line arguments to run:--use-implicit-console-appender Crtmpserver.lua represents the print console log, and using Crtmpserver.lua in the working directory as the configuration file, set the working directory to $ (OutDir) The corresponding directory of the variable is actually crtmpserver-717\builders\vs2010\debug, The execution files and library files after the final compilation of our program are placed in this directory:

We can open the following file in the directory where the file was generated after the successful compilation, the directory is the builders/vs2010/debug/directory:

Directly click on the VS2010 menu "Start Without Debugging", so that the CMD Output window after the final output is finished, will output a line "please press any key to continue ..." Otherwise flashing and error can not be seen clearly.

After running, simply report the following error:

Program crashes directly, the original OpenSSL related DLL is not copied to our program directory, we copy it here:

Continue to run, found the following error:

We removed the SSL permissions in the configuration file to verify related content:

After commenting out the relevant node, continue to run, still error:

There is a problem with the path setting for the log specified in the error display configuration, continue modifying the configuration as follows:

Run again, the display runs successfully, the interface is as follows:

Push the stream to Crtmpserver

After compiling successfully crtmpserver, we tried to push the live stream to the server and then live it. Without the camera, we can use open-source OBS software to push live streaming, download and install will not say, I believe that the game live broadcast how much to understand. Here is the interface after OBS opens:

To set up a video capture source:

Click the "Settings" button in the bottom right corner of the main interface to enter the push flow parameter settings, we mainly set the "streaming" tab content, crtmpserver configuration file is configured by default live this push-flow point, so our push-flow path is rtmp://127.0.0.1/live/ Just set a live stream name, for example, here is test, set it up, then click OK.

Then click on the "Start streaming" button on the main interface to start the flow, and you can see that after the push flow is successful, there will be some logs printed in the console window of our crtmpserver run:

From the last two lines of the log we can see that the stream test has been successfully registered.

Play live stream from Crtmpserver

How to play the stream just pushed, we find a player that supports RTMP protocol, the latest version of VLC should be supported for RTMP protocol playback. In addition the Flash Player is also a good choice to enter the address and stream name in the player:

The playback effect is as follows, the computer desktop is truncated:

To this, our entire crtmpserver source of the Windows platform of the compilation, Linux platform compilation, push stream, play even if complete. You can see that the compilation of Windows is more complex than Linux, in fact, a lot of open source software for Linux to be more friendly, including compiling the process of running a bit smoother. Later in the chapter, we will begin to analyze the schema of the Crtmpserver, the details of the RTMP protocol, the format of the MP4 file, and finally we will implement the HLS function (native crtmpserver is not HLS).

If this article is helpful to you, your likes, will let me have the greater confidence to write well the later article.

Crtmpserver Series (b): Set up a simple streaming media live system

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.