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. Creating a video file in Qt
QtWS25 Last Chance

Creating a video file in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
video file
13 Posts 6 Posters 4.2k 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.
  • mrjjM mrjj

    Hi
    For fast way, i would just use ffmpeg
    http://hamelot.io/visualization/using-ffmpeg-to-convert-a-set-of-images-into-a-video/
    with QProcess.

    As creating a mp4 from scratch is pretty involving due to codex compressing and all the header info.

    ffmpeg runs on linux, mac and windows so its only if u use android it would be a bad idea.

    NIXINN Offline
    NIXINN Offline
    NIXIN
    wrote on last edited by
    #4

    @mrjj Thanks for your response. Based on your suggestion I tried this:

    void Video::slot_generateVideo()
    {
    QStringList arguments;
    QString imgPath("home/uidm9805/images/pic%04d.png");
    int fps = 2;
    QString frameRate;
    QString compressionLevel("image2");
    QString resolution("1920x1080");
    QString startFrame("1");
    QString videoFrames("1000");
    QString codec("libx264");
    QString quality("25");
    QString pixelFormat("yuv420p");
    QString outputFile("\"home/uidm9805/images/test.mp4\"");
    
    arguments << "-r";
    arguments << frameRate.setNum(fps);
    
    arguments << "-f";
    arguments << compressionLevel;
    
    arguments << "-s";
    arguments << resolution;
    
    arguments << "-start_number";
    arguments << startFrame;
    
    arguments << "-i";
    arguments << imgPath;
    
    arguments << "-vframes";
    arguments << videoFrames;
    
    arguments << "-vcodec";
    arguments << codec;
    
    arguments << "-crf";
    arguments << quality;
    
    arguments << "-pix_fmt";
    arguments << pixelFormat;
    
    arguments << outputFile;
    
    qDebug() << arguments;
    videoProcess = new QProcess(this);
    connect(videoProcess, SIGNAL(started()), this, SLOT(monitorStarted()));
    connect(videoProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(monitorError(QProcess::ProcessError)));
    connect(videoProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
    videoProcess->start("ffmpeg", arguments);
    videoProcess->waitForFinished(-1);
    }
    
    void Video::monitorStarted()
    {
        qDebug() << "Video Process started";
    }
    
    void Video::monitorError(QProcess::ProcessError error)
    {
        qDebug() << "Video Process error: " << error;
    }
    
    void Video::readOutput()
    {
        qDebug() << videoProcess->readAllStandardOutput();
    }
    

    I am working on ubuntu.
    when I run the same set of commands from terminal everything is working fine, test.mp4 is generated.
    But using QProcess, I got this output:
    Video Process error: 0
    I don't understand what might be the problem, any help will be appreciable.
    Thank you

    jsulmJ 1 Reply Last reply
    0
    • NIXINN NIXIN

      @mrjj Thanks for your response. Based on your suggestion I tried this:

      void Video::slot_generateVideo()
      {
      QStringList arguments;
      QString imgPath("home/uidm9805/images/pic%04d.png");
      int fps = 2;
      QString frameRate;
      QString compressionLevel("image2");
      QString resolution("1920x1080");
      QString startFrame("1");
      QString videoFrames("1000");
      QString codec("libx264");
      QString quality("25");
      QString pixelFormat("yuv420p");
      QString outputFile("\"home/uidm9805/images/test.mp4\"");
      
      arguments << "-r";
      arguments << frameRate.setNum(fps);
      
      arguments << "-f";
      arguments << compressionLevel;
      
      arguments << "-s";
      arguments << resolution;
      
      arguments << "-start_number";
      arguments << startFrame;
      
      arguments << "-i";
      arguments << imgPath;
      
      arguments << "-vframes";
      arguments << videoFrames;
      
      arguments << "-vcodec";
      arguments << codec;
      
      arguments << "-crf";
      arguments << quality;
      
      arguments << "-pix_fmt";
      arguments << pixelFormat;
      
      arguments << outputFile;
      
      qDebug() << arguments;
      videoProcess = new QProcess(this);
      connect(videoProcess, SIGNAL(started()), this, SLOT(monitorStarted()));
      connect(videoProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(monitorError(QProcess::ProcessError)));
      connect(videoProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
      videoProcess->start("ffmpeg", arguments);
      videoProcess->waitForFinished(-1);
      }
      
      void Video::monitorStarted()
      {
          qDebug() << "Video Process started";
      }
      
      void Video::monitorError(QProcess::ProcessError error)
      {
          qDebug() << "Video Process error: " << error;
      }
      
      void Video::readOutput()
      {
          qDebug() << videoProcess->readAllStandardOutput();
      }
      

      I am working on ubuntu.
      when I run the same set of commands from terminal everything is working fine, test.mp4 is generated.
      But using QProcess, I got this output:
      Video Process error: 0
      I don't understand what might be the problem, any help will be appreciable.
      Thank you

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #5

      @NIXIN "QString imgPath("home/uidm9805/images/pic%04d.png");" you're missing / in front of home. Also why do you have % in file name?
      Same here QString outputFile("\"home/uidm9805/images/test.mp4\""); and remove \" as Qt will do it for you.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • NIXINN Offline
        NIXINN Offline
        NIXIN
        wrote on last edited by
        #6

        I tried giving the following paths:

        QString folderName ="images/pic"
        QString imgPath("/home/uidm9805/" + folderName + "%04d.png");
        QString outputFile("/home/uidm9805/images/test.mp4"); 
        

        still not working, getting same errors

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #7

          Hi
          Code seems fine.
          try with full path to ffmpeg
          also
          folderName ="images/pic"

          Depending on how it uses this, it might not be correct.

          NIXINN 2 Replies Last reply
          0
          • mrjjM mrjj

            Hi
            Code seems fine.
            try with full path to ffmpeg
            also
            folderName ="images/pic"

            Depending on how it uses this, it might not be correct.

            NIXINN Offline
            NIXINN Offline
            NIXIN
            wrote on last edited by
            #8

            @mrjj
            Tried this

            videoProcess->start("usr/bin/ffmpeg", arguments);
            

            but got the same errors.

            jsulmJ 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              Code seems fine.
              try with full path to ffmpeg
              also
              folderName ="images/pic"

              Depending on how it uses this, it might not be correct.

              NIXINN Offline
              NIXINN Offline
              NIXIN
              wrote on last edited by
              #9

              @mrjj

              folderName ="images/pic"
              
              Depending on how it uses this, it might not be correct.
              

              Can you explain this please.....

              mrjjM 1 Reply Last reply
              0
              • NIXINN NIXIN

                @mrjj

                folderName ="images/pic"
                
                Depending on how it uses this, it might not be correct.
                

                Can you explain this please.....

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @NIXIN

                If something just appends that to other path or use it relative,
                it might not work as expected.
                Like
                somewhere = "/home"
                open (somewhere + folderName )
                "/homeimages/pic"
                and so one.
                but if it adds / when doing + , all is fine.

                since there is no error reported with QProcess i assume it runs the app but app do not produce output for some reason.

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

                  Hi,

                  You are missing the leading / in your path to 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
                  • NIXINN NIXIN

                    @mrjj
                    Tried this

                    videoProcess->start("usr/bin/ffmpeg", arguments);
                    

                    but got the same errors.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @NIXIN said in Creating a video file in Qt:

                    usr/bin/ffmpeg

                    Please take a closer look at the path. You're doing same mistake over and over even after it was pointed out.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2
                    • NIXINN NIXIN

                      I want to make a video file (.avi or .mp4) in qt. Through some online sources I came to know that video can be made by combining QImages into a single file, but I don't know how to exactly do that. Any lead will be helpful

                      A different approach is also welcomed......

                      V Offline
                      V Offline
                      Vijaykarthikeyan
                      wrote on last edited by
                      #13

                      @NIXIN you can use opencv to write the frames into .avi or any other format you want to write.

                      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