Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. streaming MJPEG via CGI on nginx / lighty
  2. // As soon as someone connects  
  3. fprintf (stdout, "Connection: close"
  4.                  "rn"
  5.                  "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0"
  6.                  "rn"
  7.                  "Pragma: no-cache"
  8.                  "rn"
  9.                  "Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY
  10.                  "rn"
  11.                  "rn"
  12.                  "--" BOUNDARY "rn");
  13.  
  14. [...]
  15.  
  16. while (1) {
  17.  
  18.     //Magically take the frame from the shared memory
  19.  
  20.     fprintf(stdout, "Content-Type: image/jpegrn"
  21.                     "Content-Length: %drn"
  22.                     "rn", frame_length);
  23.  
  24.     DBG("sending framen");
  25.     if ((fwrite(frame_data, frame_length, sizeof (char) , stdout)) == 0 ) {
  26.         ERR ("Error sending frame");
  27.         break;
  28.     }
  29.  
  30.     DBG("sending boundaryn");
  31.     fprintf(stdout, "rn--" BOUNDARY "rn");
  32.     }