How to Create a HTTP MJPEG Streaming Server With QTcp-Server Sockets?

后端 未结 1 518
广开言路
广开言路 2020-12-03 19:46

I want to create a Http Server to send an MJPEG Stream. I\'m Already able to send an Image but no Live-Stream.

What I did: Created an TCP-Server. When a client Conn

相关标签:
1条回答
  • 2020-12-03 20:20

    I solved it myself.... I just had to adjust some Protocol releated things....

    m_TcpHttpClient->readAll(); // Discard "Get Request String"
    
    QByteArray ContentType = ("HTTP/1.0 200 OK\r\n" \
                              "Server: en.code-bude.net example server\r\n" \
                              "Cache-Control: no-cache\r\n" \
                              "Cache-Control: private\r\n" \
                              "Content-Type: multipart/x-mixed-replace;boundary=--boundary\r\n\r\n");
    
    m_TcpHttpClient->write(ContentType);
    
    
    while(1){
    
        // Image to Byte Array via OPENCV Method
        std::vector<uchar> buff;
        imencode(".jpg",m_VisualEngine->GetActualFrame(),buff);
        std::string content(buff.begin(), buff.end());
        QByteArray CurrentImg(QByteArray::fromStdString(content));
    
    
        QByteArray BoundaryString = ("--boundary\r\n" \
                                     "Content-Type: image/jpeg\r\n" \
                                     "Content-Length: ");
    
        BoundaryString.append(QString::number(CurrentImg.length()));
        BoundaryString.append("\r\n\r\n");
    
        m_TcpHttpClient->write(BoundaryString);
        m_TcpHttpClient->write(CurrentImg); // Write The Encoded Image
    
        m_TcpHttpClient->flush();
    }
    
    0 讨论(0)
提交回复
热议问题