Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Streaming video over network
Qt 6.11 is out! See what's new in the release blog

Streaming video over network

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 9.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vili22
    wrote on last edited by
    #1

    Hi, I would like to create a QT application that views a video that is streamed over a network from my rasberry pi. I can stream the video from my rasberry using netcat and then I can view it on my laptop using netcat + mplayer. However, now I would like to create my own Qt application that reads the stream and views it. At this point I have tried the code below, but the readyRead() signal is never emitted and if I try to play the stream anyway I get the error message "stream contains no data". I'm very new to network programming and I would highly appreciate any help to solve the problem.

    code:

    @
    player = new QMediaPlayer(this);
    videoWidget = new VideoWidget(this);
    videoWidget->setMinimumSize(400,100);
    player->setVideoOutput(videoWidget);

    tcpserver = new QTcpServer(this);
    QHostAddress hostadd(IPaddress); // IPaddress is the Laptop's IP address
    tcpserver->listen(hostadd,port); //the port is the same as the port were the data is streamed from the rasberry

    con_socket=new QTcpSocket;
    connect(con_socket,SIGNAL(hostFound()),this,SLOT(hostIsFound()));
    connect(con_socket,SIGNAL(connected()),this,SLOT(connectionEstablished()));
    connect(con_socket,SIGNAL(readyRead()),this,SLOT(playStream()));
    connect(con_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(connectionError(QAbstractSocket::SocketError)));
    con_socket->connectToHost(IPaddress,port);

    void Player::playStream(){
    player->setMedia(QMediaContent(), con_socket);
    if (con_socket->canReadLine()){
    player->play();
    }
    }
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seba84
      wrote on last edited by
      #2

      There is something I do not understand of your code. Shouldn't the Qt application be the client side one? If yes, why are you creating a QTcpServer object? I am not an expert, but I think you are making a loop, meaning that the Qt application is both server and client (I don't know if that is possible). You should only do all the streaming with the QTcpSocket object only.

      Did you saw the following doc links?
      "Networking and Connectivity":http://qt-project.org/doc/qt-5/topics-network-connectivity.html
      "Fortune Server Example":http://qt-project.org/doc/qt-5/qtnetwork-fortuneserver-example.html
      "Fortune Client Example":http://qt-project.org/doc/qt-5/qtnetwork-fortuneclient-example.html

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vili22
        wrote on last edited by
        #3

        Hi, yes in the first place I also assumed that I should only run the client part. However, in that case I got on error when I call the connectToHost() function. I also tried to use the QUdpsocket and the bind function. In this case I'm able to bind to port but I'm no more able to stream from the rasberry (if I have the server running rasberry keeps streaming, but I'm not able to catch the stream).

        I have read the examples suggested. However, I'm not sure how to apply those examples in this case, because I'm working with a continuous stream of data.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Seba84
          wrote on last edited by
          #4

          Maybe you need to apply the synchronous (blocking) approach. See the "Blocking Fortune Client Example":http://qt-project.org/doc/qt-5/qtnetwork-blockingfortuneclient-example.html.

          But be carefull that in this case you will need to do "multi-threading":http://qt-project.org/doc/qt-5/thread-basics.html.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vili22
            wrote on last edited by
            #5

            Hi, I managed to make some process. No I can get the stream to the mediaplayer using the below code. However, the player is not able to play the stream (.h264 format) and I get errors like

            bq. Error: "Could not determine type of stream."
            appsrc: push buffer wrong state
            ** (video_player:5372): CRITICAL **: gst_type_find_helper_for_buffer: assertion `GST_BUFFER_OFFSET (buf) == 0 || GST_BUFFER_OFFSET (buf) == GST_BUFFER_OFFSET_NONE' failed .

            I'm however able to play a recorded sample from a file using the player. Also in this case I got errors like

            bq. Warning: "A lot of buffers are being dropped."

            and some video frames are missing. So I'm not sure if I'm missing some plugins or if I should somehow modify the stream before passing it to the player?

            @player = new QMediaPlayer(this);
            videoWidget = new VideoWidget(this);
            videoWidget->setMinimumSize(400,100);
            player->setVideoOutput(videoWidget);

            tcpserver = new QTcpServer(this);
            QHostAddress hostadd(IPaddress); // IPaddress is the Laptop's IP address
            tcpserver->listen(hostadd,port); //the port is the same as port were the data is streamed from the rasberry
            connect(tcpserver, SIGNAL(newConnection()), this, SLOT(streamFound()));

            void Player::streamFound(){
            con_socket= tcpserver->nextPendingConnection();
            connect(con_socket,SIGNAL(readyRead()),this,SLOT(playStream()));
            }

            void Player::playStream(){
            player->setMedia(QMediaContent(),con_socket);
            if (con_socket->canReadLine()){
            player->play();
            }
            }@

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved