Ticker

6/recent/ticker-posts

Header Ads Widget

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

Introduction

Recently I took a better have a look at Nex Gen Media Server (NGMS) and their API framework. NGMS is a multi-purpose streaming server which helps among the a la mode streaming protocols corresponding to RTSP, RTMP, Apple's HTTP Live, and MPEG-2 Transport Stream. NGMS comes with transcoding help and is ready to seize and reformat reside video streams and adapt them to be obtained by one other rather system, corresponding to capturing an HD video feed and high-power it to be obtained by an iPhone over 3g. My focus was to combine the NGMS API to regulate the streaming options instantly from my very own C computer software. In this instance I'm utilizing Ubuntu Linux 10.04.


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

The very first affair is to obtain and browse the NGMS User Guide and the API reference information for Nex Gen Media Server. (These hyperlinks are positioned on the backside of the article) There are many configuration choices in there all the same we are going to simply follow the fundamentals. Then you should obtain the NGMS bundle for linux. The model I used was NGMS v1.3.4. Once you obtain the bundle simply unzip the contents right into a listing of your alternative. I used ~/ngmsStreaming

Setting up the appliance.

To combine NGMS instantly into my C computer software I requisite to embrace "ngms/include/ngmslib.h" into my code.

When constructing my computer software I requisite to embrace the libraries ngms/lib/libngms.so and ngms/lib/libxcode.so. It appears that libngms.so additionally relies on libcrypto.so, which must be nominal inside the linker choices.

Here is the straightforward makefile that I'm utilizing:

#Example Makefile

CC=gcc
CFLAGS=-ggdb
INCLUDES+= -I ngms/embrace
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 computer software
*
*/

typedef unsigned int uint32_t;
typedef unsigned prolonged prolonged uint64_t;
#embrace
#embrace "ngmslib.h"

int predominant(int argc, char *argv[]) {
NGMSLIB_STREAM_PARAMS_T ngmsConfig;
NGMS_RC_T returnCode;

returnCode = ngmslib_open(&ngmsConfig);
if(NGMS_RC_OK!= returnCode) {
fprintf(stderr, "ngmslib_open failedn");
return -1;
}

ngmsConfig.inputs[0] = "mediaTestFile.mp4";
ngmsConfig.output = "rtp://127.0.0.1:5004";

returnCode = ngmslib_stream(&ngmsConfig);
if(NGMS_RC_OK!= returnCode) {
fprintf(stderr, "ngmslib_open failedn");
}

ngmslib_close(&ngmsConfig);

return 0;
}

The above code makes use of the NGMSLIB_STREAM_PARAMS_T struct kind to regulate the ngms library. The very first affair that must be performed is a name to ngmslib_open to "preset" the struct. After that you could fill out any of the choices inside the struct to regulate what NGMS will do. Then you'll be able to "ngmslib_stream" to create the output video.

I'm in a position to open the stream in VLC player and play the video.

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

Viola! It was that simple!!! I can now stream a media file instantly from my computer software!

Since the ngmslib_stream perform name is a block operation, to interrupt the stream I can name ngmslib_close from one other thread and the ngmslib_stream name will exit.

I accustomed be ready so as to add help for an embedded Flash player by including the next strains of code.

ngmsConfig.rtmplive = "1935";
ngmsConfig.reside = "8080";

With my browser I get hitched with localhost:8080/reside and I get again a webpage with flash player taking part in the video.

Instead of taking part in a file I can change the enter to be a reside video stream. I can create two separate cases of my computer software. One occasion will output the video to port 5006. The different occasion 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://127.0.0.1:5006";
ngmsConfig.strfilters[0] = "type=m2t";

Conclusion

These few examples present its fairly simple so as to add video streaming help into your individual computer software. I've used C right here. If your computer software is C++ you'll be able to wrap all of the calls to ngmslib utilizing the "extern "C" " key phrase. You power additionally know in Java all the same it could required constructing a JNI interface to wrap every of the calls all the way down to NGMS.

This was a fairly easy instance. In the approximately future I'll go over how the NGMS library can be used to construct your individual video streaming shopper.


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

Post a Comment

0 Comments