c - Grab one image frame from MJPEG stream -


i have videosec ip camera, , daemon running on embedded linux npe controler. daemon needs gram images ip camera, part implemented libcurl in standard way, , axis camera working fine:

static size_t write_data(void *ptr, size_t size, size_t nmemb, file *stream) {      size_t written = fwrite(ptr, size, nmemb, stream);      return written; }  void refreshcameraimage(char *target, char *url) {      curl *image;      curlcode imgresult;      file *fp;       image = curl_easy_init();       if (image)      {           fp = fopen(target, "wb");           if(fp == null)           printf("\nfile cannot opened");             curl_easy_setopt(image, curlopt_url, url);           curl_easy_setopt(image, curlopt_writefunction, null);           curl_easy_setopt(image, curlopt_writedata, fp);            imgresult = curl_easy_perform(image);           if( imgresult )           {                printf("\ncannot grab image!");           }      }      curl_easy_cleanup(image);      fclose(fp); } 

problem videosec camera cannot define jpeg stream, mjpeg. so, need way grab 1 frame mjpeg stream libcurl. opencv not option.

in m-jpeg, jpeg images embedded intact , separated textual separators subheaders. extracting jpeg easy thing:

  • you locate first/next subheader/separator in response body
  • you locate content-length value, if available
  • you skip \r\n\r\n locate beginning of jpeg data
  • you receive jpeg data either content-length number of bytes, or if length unavailalble, read until next separator

the resulting data jpeg file/image/stream.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -