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.
  • P Offline
    P Offline
    Pablo J. Rogina
    wrote on 6 Feb 2018, 18:47 last edited by
    #3

    @NIXIN what about trying with a QML Camera component?

    Upvote the answer(s) that helped you solve the issue
    Use "Topic Tools" button to mark your post as Solved
    Add screenshots via postimage.org
    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • M mrjj
      6 Feb 2018, 15:21

      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.

      N Offline
      N Offline
      NIXIN
      wrote on 15 Feb 2018, 09:14 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

      J 1 Reply Last reply 15 Feb 2018, 09:26
      0
      • N NIXIN
        15 Feb 2018, 09:14

        @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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 15 Feb 2018, 09:26 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
        • N Offline
          N Offline
          NIXIN
          wrote on 15 Feb 2018, 09:46 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
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 15 Feb 2018, 10:16 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.

            N 2 Replies Last reply 15 Feb 2018, 10:20
            0
            • M mrjj
              15 Feb 2018, 10:16

              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.

              N Offline
              N Offline
              NIXIN
              wrote on 15 Feb 2018, 10:20 last edited by
              #8

              @mrjj
              Tried this

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

              but got the same errors.

              J 1 Reply Last reply 16 Feb 2018, 05:23
              0
              • M mrjj
                15 Feb 2018, 10:16

                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.

                N Offline
                N Offline
                NIXIN
                wrote on 15 Feb 2018, 10:22 last edited by
                #9

                @mrjj

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

                Can you explain this please.....

                M 1 Reply Last reply 15 Feb 2018, 10:52
                0
                • N NIXIN
                  15 Feb 2018, 10:22

                  @mrjj

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

                  Can you explain this please.....

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 15 Feb 2018, 10:52 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 15 Feb 2018, 16:39 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
                    • N NIXIN
                      15 Feb 2018, 10:20

                      @mrjj
                      Tried this

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

                      but got the same errors.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 16 Feb 2018, 05:23 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
                      • N NIXIN
                        6 Feb 2018, 06:17

                        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 4 May 2024, 04:26 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