Welcome! Log In Create A New Profile

Advanced

Beginner developer question: streaming mjpeg in nginx

February 08, 2012 06:32AM
Hi to all,

I'd like to stream live, continuous Motion JPEG throught nginx web
server. Right now, I have a little program that captures the frames from
my hardware, separates them with boundaries and send them to stdout.
Here's, schematically, what my program does:

// As soon as someone connects

fprintf (stdout, "Connection: close"\
"\r\n" \
"Cache-Control: no-store, no-cache, must-revalidate,
pre-check=0, post-check=0, max-age=0" \
"\r\n" \
"Pragma: no-cache" \
"\r\n" \
"Content-Type: multipart/x-mixed-replace;boundary="
BOUNDARY \
"\r\n" \
"\r\n" \
"--" BOUNDARY "\r\n");

[...]

while (1) {

//Magically take the frame from the shared memory

fprintf(stdout, "Content-Type: image/jpeg\r\n" \
"Content-Length: %d\r\n" \
"\r\n", frame_length);

DBG("Sending MJPEG frame\n");

if ((fwrite(frame_data, frame_length, sizeof (char) , stdout)) == 0 ) {
ERR ("Error sending frame");
break;
}

DBG("Sending boundary\n");

fprintf(stdout, "\r\n--" BOUNDARY "\r\n");
}



I've seen examples of nginx modules that stream h264 files, but this
case is quite different: live streaming means a potentially infinite
MJPEG stream and no buffering done by the webserver.

I'm an nginx beginner, so I'm asking for some directions.

How can I stream this (potentially infinite) series of frames? A CGI is
sufficient o will I need to write a module? Is it even possible to do
something like this with nginx?

Thanks,
Cristiano.

--
Belloni Cristiano
Imavis Srl.
www.imavis.com http://www.imavis.com
belloni@imavis.com <mailto://belloni@imavis.com>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Beginner developer question: streaming mjpeg in nginx

cristiano.belloni February 08, 2012 06:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 186
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready