Transferring a video file (.mp4) through Ethernet port.
-
@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
-
@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...
-
@Christian-Ehrlicher I'm sorry, I did not get where the issue is, can you please elaborate, which part of code should be modified ?
-
@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 ofplayer
andbuffer
. -
@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.
-
@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(); }
-
@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 somethingdelete
s it. The fact thatQMediaPlayer *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 fromQBuffer buffer(&received_data)
, which is a local stack variable, not a pointer to an object. That does get destroyed at the end of theif
.Secondly,
player->setMedia(QMediaContent(), &buffer)
means thatplayer
is using the stackbuffer
, so as soon as theif
exitsbuffer
is destroyed but theQMediaPlayer
is still using it as its buffer. When you goplayer->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.