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. Transferring a video file (.mp4) through Ethernet port.

Transferring a video file (.mp4) through Ethernet port.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtnetworkqtcpsocketqtmultimedia
17 Posts 5 Posters 1.4k Views
  • 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.
  • P Prakash08
    16 Apr 2024, 06:56

    @J-Hilk it is also created when the receiveVideo() is called .. it exists until the function returns ..

    J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 16 Apr 2024, 07:02 last edited by
    #8

    @Prakash08 no, it's on the heap and you actually never delete it, so it exists forever.

    Maybe QVideoWidgets takes ownership of it? I would have to look that up

    either way the core issue stays, you're trying to play data that is destroyed as soon as it's created


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    1
    • P Offline
      P Offline
      Prakash08
      wrote on 16 Apr 2024, 07:10 last edited by
      #9

      @ChrisW67 the video is 5 secs long. And how to give the condition in sender to code to disconnect the connection when its done sending data ..?

      C 1 Reply Last reply 16 Apr 2024, 08:15
      0
      • P Offline
        P Offline
        Prakash08
        wrote on 16 Apr 2024, 07:20 last edited by
        #10

        @J-Hilk the main issue is, "Error: failed to seek". this is the message i'm getting. what does this mean? how to solve this ? any idea ?

        C 1 Reply Last reply 16 Apr 2024, 07:23
        0
        • P Prakash08
          16 Apr 2024, 07:20

          @J-Hilk the main issue is, "Error: failed to seek". this is the message i'm getting. what does this mean? how to solve this ? any idea ?

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 16 Apr 2024, 07:23 last edited by
          #11

          @Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:

          how to solve this ? any idea ?

          Fix your code - 4 people told you what's wrong...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • P Offline
            P Offline
            Prakash08
            wrote on 16 Apr 2024, 07:33 last edited by
            #12

            @Christian-Ehrlicher I'm sorry, I did not get where the issue is, can you please elaborate, which part of code should be modified ?

            1 Reply Last reply
            0
            • J JonB
              16 Apr 2024, 06:48

              @Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:

                  // Set the media content of the QMediaPlayer
                  player->setMedia(QMediaContent(), &buffer);
              

              player is using &buffer as its buffer. Compare the lifetimes of player and buffer.

              J Offline
              J Offline
              JonB
              wrote on 16 Apr 2024, 07:34 last edited by JonB
              #13

              @Christian-Ehrlicher said in Transferring a video file (.mp4) through Ethernet port.:

              QBuffer buffer(&received_data);

              How long does this object live?

              @JonB said in Transferring a video file (.mp4) through Ethernet port.:

              player is using &buffer as its buffer. Compare the lifetimes of player and buffer.

              P 1 Reply Last reply 16 Apr 2024, 09:50
              0
              • P Prakash08
                16 Apr 2024, 07:10

                @ChrisW67 the video is 5 secs long. And how to give the condition in sender to code to disconnect the connection when its done sending data ..?

                C Offline
                C Offline
                ChrisW67
                wrote on 16 Apr 2024, 08:15 last edited by
                #14

                @Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:

                And how to give the condition in sender to code to disconnect the connection when its done sending data ..?

                When the sender runs out of file content, or send its entire in-memory buffer, then it should call close() on its socket. Exactly how that looks depends on your sender code.

                P 1 Reply Last reply 16 Apr 2024, 09:39
                0
                • C ChrisW67
                  16 Apr 2024, 08:15

                  @Prakash08 said in Transferring a video file (.mp4) through Ethernet port.:

                  And how to give the condition in sender to code to disconnect the connection when its done sending data ..?

                  When the sender runs out of file content, or send its entire in-memory buffer, then it should call close() on its socket. Exactly how that looks depends on your sender code.

                  P Offline
                  P Offline
                  Prakash08
                  wrote on 16 Apr 2024, 09:39 last edited by
                  #15

                  @ChrisW67 how to send its in-memory buffer ? And here is the sender code ..

                  void MainWindow::send_video()
                  {
                      qDebug()<<"Connected to Server:"<<socket->peerAddress()<<" on port:"<<socket->peerPort()<<" name:"<<socket->peerName();
                      // QFile file("C:/Users/Intel/Pictures/sunset.png"); // Replace with the actual video path
                      QFile file("C:/Users/Intel/Desktop/video_2.mp4");
                      if (!file.open(QIODevice::ReadOnly)) {
                          qDebug() << "Unable to open file:" << file.errorString();
                          return;
                      }
                  
                      while (!file.atEnd()) {
                          QByteArray imageData = file.readAll(); // Read data in chunks
                          socket->write(imageData); // Send data to server
                          qDebug()<<" video data ..";
                      }
                  
                      // QByteArray imageData = file.read(16955); // Read data in chunks
                      // socket->write(imageData);
                  
                      qDebug()<<" video data sent..";
                      file.close();
                      socket->disconnectFromHost();
                  }
                  
                  1 Reply Last reply
                  0
                  • J JonB
                    16 Apr 2024, 07:34

                    @Christian-Ehrlicher said in Transferring a video file (.mp4) through Ethernet port.:

                    QBuffer buffer(&received_data);

                    How long does this object live?

                    @JonB said in Transferring a video file (.mp4) through Ethernet port.:

                    player is using &buffer as its buffer. Compare the lifetimes of player and buffer.

                    P Offline
                    P Offline
                    Prakash08
                    wrote on 16 Apr 2024, 09:50 last edited by
                    #16

                    @JonB In the provided code , the player and buffer objects are created locally within the receiveVideo() function scope. Their lifetime is limited to the duration of the function execution.

                    J 1 Reply Last reply 16 Apr 2024, 11:18
                    0
                    • P Prakash08
                      16 Apr 2024, 09:50

                      @JonB In the provided code , the player and buffer objects are created locally within the receiveVideo() function scope. Their lifetime is limited to the duration of the function execution.

                      J Offline
                      J Offline
                      JonB
                      wrote on 16 Apr 2024, 11:18 last edited by
                      #17

                      @Prakash08
                      Sorry, but you're wrong. @Christian-Ehrlicher & I have both tried to point this out to you.

                      First of all, QMediaPlayer *player = new QMediaPlayer is a pointer to an allocated object on the heap. That means it persists until something deletes it. The fact that QMediaPlayer *player is itself a local variable is neither here nor there, when it goes out of scope that does not destroy the object it points to. That is quite different from QBuffer buffer(&received_data), which is a local stack variable, not a pointer to an object. That does get destroyed at the end of the if.

                      Secondly, player->setMedia(QMediaContent(), &buffer) means that player is using the stack buffer, so as soon as the if exits buffer is destroyed but the QMediaPlayer is still using it as its buffer. When you go player->play() at the end that only starts playing the video, it does not finish playing it. It carries on playing after the function exits. But it's reading from a buffer which has now been destroyed. Not good! Lucky it does not "crash". Your "Error:failed to seek" error may be from code trying to access it when it is no longer valid.

                      This is all standard C++ stuff.

                      1 Reply Last reply
                      4

                      17/17

                      16 Apr 2024, 11:18

                      • Login

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