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 start filename args
Forum Updated to NodeBB v4.3 + New Features

QProcess start filename args

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 1.7k Views 2 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.
  • PsnarfP Psnarf

    Thank you for your reply. Things work as advertised in a bash shell. It is the argument in QProcess::start() as that is passed to the shell I'm trying to get at. "ffmpeg -i file" - it is only from qprocess that it does not recognize the -i option.

    jeremy_kJ Offline
    jeremy_kJ Offline
    jeremy_k
    wrote on last edited by
    #7

    @Psnarf said in QProcess start filename args:

    Thank you for your reply. Things work as advertised in a bash shell. It is the argument in QProcess::start() as that is passed to the shell I'm trying to get at. "ffmpeg -i file" - it is only from qprocess that it does not recognize the -i option.

    Rather than attempting to guess what QProcess is passing to ffmpeg, have QProcess execute the above script with the same arguments. Look at the output file, and adjust as necessary.

    outFileName = filename.chopped(3) + "aac";
    QString program("/tmp/test.sh");
    QStringList args;
    args << " -i " << filename << " -vn -c:a copy " << outFileName;
    myProcess->setProgram(program);
    myProcess->setArguments(args);
    myProcess->start();
    myProcess->waitForFinished();
    // Examine /tmp/test
    

    Asking a question about code? http://eel.is/iso-c++/testcase/

    1 Reply Last reply
    1
    • JonBJ JonB

      @Psnarf

      args << " -i " << filename << " -vn -c:a copy " << outFileName;
      

      Your arguments look wrong in a couple of ways.

      For the -i issue, I would presume that is because you have included spaces in the argument. When you pass " -i " you are passing a single argument which is space-hyphen-i-space. This is going to upset ffmpeg. Look very carefully at the error message you have copied. I paste it here from your post:

      "Unable to find a suitable output format for ' -i '
      

      Note the spaces in the ' -i ' in that message.

      When you pass that to a shell it splits arguments on (non-quoted) spaces, so the situation is different.

      For the " -vn -c:a copy ", you are passing that as a single argument, which again looks as though it will be incorrect for what ffmpeg expects, in addition to the same issue of its leading and trailing spaces.

      I suspect your args should look like this:

      args << "-i" << filename << "-vn" << "-c:a" << "copy" << outFileName;
      

      ?

      PsnarfP Offline
      PsnarfP Offline
      Psnarf
      wrote on last edited by Psnarf
      #8

      @JonB
      args << "-i" << filename << "-vn" << "-c:a" << "copy" << outFileName;

      It never gets to the other arguments, it throws an error at " -i ". I added the spaces because without them, the dashes get dropped somewhere, so the error is "i" unknown option.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #9

        You must not add spaces around the arguments.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • PsnarfP Offline
          PsnarfP Offline
          Psnarf
          wrote on last edited by Psnarf
          #10

          @jeremy_k Thank you for this idea! Excellent troubleshooting tip.
          The args appear as they do in debug, a list of strings. I assume QProcess::start() appends them to program with a space before between each.
          Using Jeremy's argument list: "Failed to set value '-c:a' for option 'vn': Option not found " . If I truncate the args to args << "-i" << filename;, everything works as advertised. There is no value for -vn (no video stream). "-c:a copy" (audio codec is 'copy') is one option-value pair, not two separate options. This command takes two file arguments, "-i infile" and "outfile". Everything after the infile specifies how to build the outfile. The outfile extension specifies the format of the output file. The entire command is supposed to convert an audio/video Matroska container into an audio AAC file. I have never seen the '-c:a' option taken as the value for 'vn'.

          Christian EhrlicherC 1 Reply Last reply
          0
          • PsnarfP Psnarf

            @jeremy_k Thank you for this idea! Excellent troubleshooting tip.
            The args appear as they do in debug, a list of strings. I assume QProcess::start() appends them to program with a space before between each.
            Using Jeremy's argument list: "Failed to set value '-c:a' for option 'vn': Option not found " . If I truncate the args to args << "-i" << filename;, everything works as advertised. There is no value for -vn (no video stream). "-c:a copy" (audio codec is 'copy') is one option-value pair, not two separate options. This command takes two file arguments, "-i infile" and "outfile". Everything after the infile specifies how to build the outfile. The outfile extension specifies the format of the output file. The entire command is supposed to convert an audio/video Matroska container into an audio AAC file. I have never seen the '-c:a' option taken as the value for 'vn'.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #11

            @Psnarf said in QProcess start filename args:

            I assume QProcess::start() appends them to program with a space before between each

            No, it does not modify them but pass them as separate arguments as needed.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            PsnarfP 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Psnarf said in QProcess start filename args:

              I assume QProcess::start() appends them to program with a space before between each

              No, it does not modify them but pass them as separate arguments as needed.

              PsnarfP Offline
              PsnarfP Offline
              Psnarf
              wrote on last edited by Psnarf
              #12

              @Christian-Ehrlicher said in QProcess start filename args:

              No, it does not modify

              "...as needed"? Recall the command I'm trying to build:
              /usr/bin/ffmpeg -i infile -vn -c:a copy outfile - I need the entire command. How is -c:a taken as the value of the 'vn' option?? It is a separate option.

              Failed to set value '-c:a' for option 'vn': Option not found

              If I enter "/usr/bin/ffmpeg -i infile -vn -c:a", the expected error appears: Missing argument for option 'c:a'. Like I said, everything works in a konsole bash shell. QProcess::start() somehow does something it shouldn't.

              1 Reply Last reply
              0
              • PsnarfP Offline
                PsnarfP Offline
                Psnarf
                wrote on last edited by Psnarf
                #13

                This is how QProcess builds argv for linux:

                argv[0] = ::strdup(encodedProgramName.constData());
                   // Add every argument to the list
                   for (int i = 0; i < arguments.count(); ++i)
                       argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
                

                It then forks argv. Perhaps something in encodeName, which changes everything to local 8-bit? The documentation for encodeName says: File names hard-coded into the application should only use 7-bit ASCII filename characters. If that is the case, why are the filenames in the argument list converted to 8-bit? Should not that be an option? How can QProcess deal with this command:

                ffmpeg -i input.mp4 -c:v libx265 -preset medium -crf 28 -pix_fmt yuv420p12le -c:a aac -b:a 128k output_12bit.mp4
                
                jeremy_kJ 1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  As already said - add every parameter to a QStringList, pass it to QProcess::exec()

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • PsnarfP Psnarf

                    This is how QProcess builds argv for linux:

                    argv[0] = ::strdup(encodedProgramName.constData());
                       // Add every argument to the list
                       for (int i = 0; i < arguments.count(); ++i)
                           argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
                    

                    It then forks argv. Perhaps something in encodeName, which changes everything to local 8-bit? The documentation for encodeName says: File names hard-coded into the application should only use 7-bit ASCII filename characters. If that is the case, why are the filenames in the argument list converted to 8-bit? Should not that be an option? How can QProcess deal with this command:

                    ffmpeg -i input.mp4 -c:v libx265 -preset medium -crf 28 -pix_fmt yuv420p12le -c:a aac -b:a 128k output_12bit.mp4
                    
                    jeremy_kJ Offline
                    jeremy_kJ Offline
                    jeremy_k
                    wrote on last edited by
                    #15

                    @Psnarf said in QProcess start filename args:

                    This is how QProcess builds argv for linux:

                    argv[0] = ::strdup(encodedProgramName.constData());
                       // Add every argument to the list
                       for (int i = 0; i < arguments.count(); ++i)
                           argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
                    

                    It then forks argv. Perhaps something in encodeName, which changes everything to local 8-bit?

                    Going back to test.sh, its output should answer this question for you. Look at the file it generates. It will tell you exactly what the child process receives, because it is that child process. QProcess isn't going to alter them based on which program it is executing.

                    The documentation for encodeName says: File names hard-coded into the application should only use 7-bit ASCII filename characters. If that is the case, why are the filenames in the argument list converted to 8-bit? Should not that be an option?

                    QProcess invokes execve in the unix implementation, which accepts char *const argv[] consisting of null byte terminated strings. Not converting from utf-16 is unlikely to behave as expected.

                    Asking a question about code? http://eel.is/iso-c++/testcase/

                    PsnarfP 1 Reply Last reply
                    0
                    • jeremy_kJ jeremy_k

                      @Psnarf said in QProcess start filename args:

                      This is how QProcess builds argv for linux:

                      argv[0] = ::strdup(encodedProgramName.constData());
                         // Add every argument to the list
                         for (int i = 0; i < arguments.count(); ++i)
                             argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
                      

                      It then forks argv. Perhaps something in encodeName, which changes everything to local 8-bit?

                      Going back to test.sh, its output should answer this question for you. Look at the file it generates. It will tell you exactly what the child process receives, because it is that child process. QProcess isn't going to alter them based on which program it is executing.

                      The documentation for encodeName says: File names hard-coded into the application should only use 7-bit ASCII filename characters. If that is the case, why are the filenames in the argument list converted to 8-bit? Should not that be an option?

                      QProcess invokes execve in the unix implementation, which accepts char *const argv[] consisting of null byte terminated strings. Not converting from utf-16 is unlikely to behave as expected.

                      PsnarfP Offline
                      PsnarfP Offline
                      Psnarf
                      wrote on last edited by Psnarf
                      #16

                      I had copied my ffprobe wrapper project to create the ffmpeg wrapper. When I stepped through the program line by line, I discovered a 'ffprobe' where a 'ffmpeg' should be. Made the substitution, problem solved.
                      Cause: IBK - Idiot Behind Keyboard

                      I thank everyone who tried to help me. I learned a lot from this exercise in futility.

                      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