Results 1 to 5 of 5

Thread: Read MJPEG Stream from an ip cam

  1. #1

    Default Read MJPEG Stream from an ip cam

    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
    Last edited by mennaSiam; 3rd October 2010 at 09:05.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Read MJPEG Stream from an ip cam

    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.

  3. #3

    Default Re: Read MJPEG Stream from an ip cam

    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

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Read MJPEG Stream from an ip cam

    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?

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Read MJPEG Stream from an ip cam

    This seems highly likely to be the wrong way around:
    Qt Code:
    1. QStringList l2= imageData.split("\n\r");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. get network stream with QNetworkAccessManager
    By Remco in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2010, 16:25
  2. Xml stream
    By rk0747 in forum Qt Programming
    Replies: 3
    Last Post: 9th February 2010, 18:10
  3. Non-blocking stream read
    By akiross in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2009, 11:07
  4. QGraphicScene to stream
    By phannent in forum Newbie
    Replies: 2
    Last Post: 28th June 2008, 09:43
  5. Creating a QMovie from mjpeg
    By forrestfsu in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2007, 22:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.