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. Qprocess: howto run a command consisting of several commands chained together?
Forum Updated to NodeBB v4.3 + New Features

Qprocess: howto run a command consisting of several commands chained together?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 3.3k 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.
  • C Offline
    C Offline
    cdwijs
    wrote on last edited by
    #1

    Hi All,

    I'm writing a program that calls raspivid to record a video thru QProcess. This works great like this:

    void ExternalCamera::slotStartCapture(QString filename)
    {
        if (myProcess->state() == QProcess::Running)
        {
            qDebug()<<"Process already Running, killing";
            myProcess->kill();
            myProcess->waitForFinished(10000);
            //qDebug()<<"Process Killed";
        }
        qDebug()<<myProcess->state();
        filename.append(".h264");
        QStringList arguments;
        //arguments <<"-o" << "file.h264";    //filename
        arguments <<"-o" << filename;    //filename
        arguments <<"-n";                   //no preview
        arguments <<"--bitrate" << "1000000";//bitrate
        arguments <<"-t"<<"300000";          //time
    
    
        myProcess->setArguments(arguments);
        myProcess->setProgram("/usr/bin/raspivid");
    
        myProcess->start();
        qDebug()<<"start movie: "<<filename;
        myProcess->waitForStarted(10000);
        //qDebug()<<"Process started";
    }
    

    But now I would like to run the following command line. How can I tell QProcess to do this? Should I place this inside a .sh file, and then call the sh file?

    raspivid -t 200000 -o test16.h264 ; avconv -framerate 30 -i test16.h264 -c:v copy test16.mp4
    

    Cheers,
    Cedric

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

      Hi,

      So avconv should be called once raspivid is done, correct ?

      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
      0
      • C cdwijs

        Hi All,

        I'm writing a program that calls raspivid to record a video thru QProcess. This works great like this:

        void ExternalCamera::slotStartCapture(QString filename)
        {
            if (myProcess->state() == QProcess::Running)
            {
                qDebug()<<"Process already Running, killing";
                myProcess->kill();
                myProcess->waitForFinished(10000);
                //qDebug()<<"Process Killed";
            }
            qDebug()<<myProcess->state();
            filename.append(".h264");
            QStringList arguments;
            //arguments <<"-o" << "file.h264";    //filename
            arguments <<"-o" << filename;    //filename
            arguments <<"-n";                   //no preview
            arguments <<"--bitrate" << "1000000";//bitrate
            arguments <<"-t"<<"300000";          //time
        
        
            myProcess->setArguments(arguments);
            myProcess->setProgram("/usr/bin/raspivid");
        
            myProcess->start();
            qDebug()<<"start movie: "<<filename;
            myProcess->waitForStarted(10000);
            //qDebug()<<"Process started";
        }
        

        But now I would like to run the following command line. How can I tell QProcess to do this? Should I place this inside a .sh file, and then call the sh file?

        raspivid -t 200000 -o test16.h264 ; avconv -framerate 30 -i test16.h264 -c:v copy test16.mp4
        

        Cheers,
        Cedric

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @cdwijs
        You have 3 options!

        1. Split into two separate commands at the ;. Run the left-hand side, wait to finish, run the right-hand side, as two different QProcesses.

        2. Put that command line into a file. Run QProcess::execute("/bin/sh", QStringList() << "script.sh").

        3. Run the whole command-line as an argument to the shell:

        QProcess::execute("/bin/sh", QStringList() << "-c" << "raspivid -t 200000 -o test16.h264 ; avconv -framerate 30 -i test16.h264 -c:v copy test16.mp4")`.
        
        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