Using the Nex Gen Media Server (NGMS) API to Integrate Video Streaming Into Your Own C/C++ App


Recently I took a more in-depth have a look at Nex Gen Media Server (NGMS) and their API framework. NGMS is a multi-purpose streaming server which helps one of the vital in style streaming protocols akin to RTSP, RTMP, Apple’s HTTP Live, and MPEG-2 Transport Stream. NGMS comes with transcoding enhance and is in a position to seize and reformat are living video streams and adapt them to be gained through any other form of instrument, akin to shooting an HD video feed and changing it to be gained through an iPhone over 3g. My focal point was once to combine the NGMS API to keep watch over the streaming options immediately from my very own C software. In this case I’m the use of Ubuntu Linux 10.04.

The very first thing is to obtain and browse the NGMS User Guide and the API reference information for Nex Gen Media Server. (These hyperlinks are situated on the backside of the item) There are many configuration choices in there however we will be able to simply stick with the fundamentals. Then you want to obtain the NGMS package deal for linux. The model I used was once NGMS v1.3.4. Once you obtain the package deal simply unzip the contents right into a listing of your selection. I used ~/ngmsStreaming

Setting up the applying.

To combine NGMS immediately into my C software I needed to come with “ngms/come with/ngmslib.h” into my code.

When development my software I needed to come with the libraries ngms/lib/ and ngms/lib/ It turns out that additionally is determined by, which must be specified within the linker choices.

Here is the easy makefile that I’m the use of:

#Example Makefile



INCLUDES+= -I ngms/come with

LDFLAGS+= -L ngms/lib -lngms -xlcode -crypto

all: myapp

%.o: %.c

$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<

myapp: myapp.o

$(CC) -fpic -o myapp myapp.o $(LDFLAGS)

Here is the supply to myapp.c.



* Example myapp software



typedef unsigned int uint32_t;

typedef unsigned lengthy lengthy uint64_t;

#come with

#come with “ngmslib.h”

int major(int argc, char *argv[]) {


NGMS_RC_T returnCode;

returnCode = ngmslib_open(&ngmsConfig);

if(NGMS_RC_OK!= returnCode) {

fprintf(stderr, “ngmslib_open failedn”);

go back -1;


ngmsConfig.inputs[0] = “mediaTestFile.mp4”;

ngmsConfig.output = “rtp://”;

returnCode = ngmslib_stream(&ngmsConfig);

if(NGMS_RC_OK!= returnCode) {

fprintf(stderr, “ngmslib_open failedn”);



go back 0;


The above code makes use of the NGMSLIB_STREAM_PARAMS_T struct sort to keep watch over the ngms library. The very first thing that must be executed is a choice to ngmslib_open to “preset” the struct. After that you’ll fill out any of the choices within the struct to keep watch over what NGMS will do. Then you’ll “ngmslib_stream” to create the output video.

I’m in a position to open the movement in VLC participant and play the video.

VLC Player -> Open Network rtp://@:5004

Viola! It was once that simple!!! I will now movement a media record immediately from my software!

Since the ngmslib_stream serve as name is a blocking off operation, to break the movement I will name ngmslib_close from any other thread and the ngmslib_stream name will go out.

I used to be in a position so as to add enhance for an embedded Flash participant through including the next traces of code.

ngmsConfig.rtmplive = “1935”;

ngmsConfig.are living = “8080”;

With my browser I connect with localhost:8080/are living and I am getting again a web page with flash participant enjoying the video.

Instead of enjoying a record I will alternate the enter to be a are living video movement. I will create two separate circumstances of my software. One example will output the video to port 5006. The different example will seize the video on port 5006, and output it to port 5004. This is all you need to do.

//ngmsConfig.inputs[0] = “mediaTestFile.mp4”;

ngmsConfig.inputs[0] = “rtp://”;

ngmsConfig.strfilters[0] = “sort=m2t”;


These few examples display its beautiful simple so as to add video streaming enhance into your personal software. I’ve used C right here. If your software is C++ you’ll wrap the entire calls to ngmslib the use of the “extern “C” ” key phrase. You may additionally do it in Java however it could required development a JNI interface to wrap each and every of the calls all the way down to NGMS.

This was once a sexy easy instance. In the close to long run I will be able to pass over how the NGMS library can be utilized to construct your personal video streaming consumer.

Tags :