Hello
I'm looking to extract jpeg image data from a mjpeg stream, but I'm not sure how to do this in c++ .
The code snippet below does the job of connecting to the remote ip camera server & receives the mjpeg stream via tempBuffer variable.
// Loop and grab mjpeg stream
while(true)
{
int retval;
retval = recv(hSocket, tempBuffer, sizeof(tempBuffer)-1, 0);
if (retval==0)
{
break; // Connection has been closed
}
else if (retval==SOCKET_ERROR)
{
throw HRException("socket error while receiving.");
}
else
{
//***************************************************
//
// This is where we receive the incoming data stream
//
//***************************************************
// retval is number of bytes read
// Terminate buffer with zero
tempBuffer[retval] = 0;
}
}
The ip camera server returns the headers followed by jpeg data between --myboundary tags like so
HTTP/1.0 200 OK
Cache-Control: no-cache
Pragma: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Connection: close
Content-Type: multipart/x-mixed-replace; boundary=--myboundary
--myboundary
Content-Type: image/jpeg Content-Length: 19529
<<jpeg binary image data>
--myboundary
Content-Type: image/jpeg Content-Length: 19789
<<jpeg binary image data>
--myboundary
Continues...
My question is what would be the best solution to achieve this binary data extraction process in c++ & save to file in binary format, Any coding examples help/advice or links would be greatly appreciated.
Best Regards
Steve
PS
I've searched for days regarding this topic but can't find any examples anywhere, on windows platform using code::blocks+mingw