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. Play video using QMediaplayer from buffer and append buffer while the video playing
Forum Updated to NodeBB v4.3 + New Features

Play video using QMediaplayer from buffer and append buffer while the video playing

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 1.8k Views 3 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.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by AmrCoder
    #1

    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.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2
      1. 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.

      2. 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.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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