Play video using QMediaplayer from buffer and append buffer while the video playing
-
Hello,
I tried to play video from a buffer and append the buffer while playing so the two or more videos play after each other without any delay as they are one video, I tried to use the QMediaPlaylist and append the list during run time, it worked but there is a Noticeable delay between the videos I use this code in the play button
void MainWindow::on_pushButton_2_clicked() { player = new QMediaPlayer(this); QFile file("D:/video/first.mp4"); file.open(QIODevice::ReadOnly); arr = new QByteArray(); arr->append(file.readAll()); file.close(); buffer = new QBuffer(arr); buffer->open(QIODevice::ReadWrite); player->setVideoOutput(ui->widget); player->setMedia(QMediaContent(), buffer); player->play(); }
and a button to append the second video during the runtime which is here I make many different trys
void MainWindow::on_pushButton_3_clicked() { QFile file("D:/video/second.mp4"); file.open(QIODevice::ReadOnly); QByteArray temp = file.readAll(); //arr->append(temp, temp.size()); //first to append the QByteArray did not work buffer->write(temp.data(), temp.size()); //second write to the buffer but not work file.close(); qDebug() << "Appeneded"; }
first one which is append the array but it did not work, same as when i set the buffer to ReadWrite flage and same result, the result is that only the first video is played and it stop,
so can you help me to make this work? what i did wrong in my code let the second video not run smoothly after first video and this is the result i want.Thanks in advance <3.
-
-
you have to be very careful how you append data to a buffer. if it is a heap manageg buffer and you are appending more than the space you initially allocated then it will have to reallocatea larger chunk and will invalidate references to the previous buffer state.
-
mp4 is a contained media envolope. The streaming behaviour you are looking for is very hit or miss, depending upon the data that is stored within the mp4 container. generally mp4 streams have an "ITS" timestamp in them. When you append the second file that ITS becomes invalidated. the framework probably isn't expecting to see an ITS jump back to zero when the second container is pushed into the buffer.
-
-
Hi,
As @Kent-Dorfman rightfully noted, you can't just concatenate video files to make a new video.
If you would like to make one file from several, you should rather use tools like ffmpeg.