PDA

View Full Version : Read MJPEG Stream from an ip cam



mennaSiam
3rd October 2010, 09:01
Hi, I am trying to read mjpeg stream from an ip camera,

I am using QHttp to connect to the camera, and on readyRead signal I execute this function, Hint:: I know that ONEIMAGE is the boundry that separates an image from another one.

QString data(arr);
bool found = data.contains("----ONEIMAGE----");

if(!found) //I am still reading the same image
{
imageData= imageData.append(data);
}

else // I have finished reading the image and another image is received
{

QImage image;
//remove the headers
QStringList l2= imageData.split("\n\r");
if(l2.size()>1)
{
imageData= l2[1];
QByteArray arrd= l2[1].toAscii();
if (image.loadFromData(arrd))
{
QPixmap pixmap = QPixmap::fromImage(image);
ui.label->setPixmap(pixmap);
}
}

imageData.clear();
imageData.append(data);
}

But it's not working it can't parse the QByteArray (imageData) into a QImage

squidge
3rd October 2010, 09:41
So what is the contents of the QByteArray after you received it? Does it contain a valid header?

Are you processing the mime information correctly? The boundary is also contained in the mime header. You should not hard code it.

mennaSiam
3rd October 2010, 09:55
I know I shouldn't hard code it , at first I was getting the boundry tag in the signal of responseHeaderReceived, and I extracted the boundry tag from it, but I've hardcoded it just for testing and I am sure that it's "ONEIMAGE".

I've printed the QByteArray that I received, and it has a header at the start and then the data of the image, that's why I use split("\n\r") to remove the header and use the image data itself and parse it in a QImage

squidge
3rd October 2010, 13:40
I think we are talking about two different things.

I'm talking about the header of the image, not the header of the http request.

Do you see a valid header in the data you are passing to QImage?

If you save this data to a file, can you use an application to open the file as an image?

ChrisW67
4th October 2010, 04:45
This seems highly likely to be the wrong way around:


QStringList l2= imageData.split("\n\r");