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. How to obtain list of audio input Devices with ffmpeg
QtWS25 Last Chance

How to obtain list of audio input Devices with ffmpeg

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprocessffmpeg
3 Posts 3 Posters 1.7k 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.
  • S Offline
    S Offline
    Saviz
    wrote on 2 Mar 2023, 03:33 last edited by Saviz 3 Feb 2023, 03:43
    #1

    I have some code that uses a QProcess object to call ffmpeg executable in the background to perform some tasks.

    In this case I am trying to obtain the list of audio input device names from ffmpeg.

    Code:

    #include <QApplication>
    #include <QDebug>
    #include <QProcess>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QProcess process;
        QStringList arguments;
         
        arguments
                  << "-hide_banner"
                  << "-nostats"
                  << "-list_devices"
                  << "true"
                  << "-f"
                  << "dshow"
                  << "-i"
                  << "dummy";
        
        
        
            process.start("Path/to/ffmpeg", arguments);
        
            process.waitForFinished();
        
            // I use standard error because the "dummy" argument seems to raise a warning/error
            QByteArray output = process.readAllStandardError();
        
        
            qDebug() << output;
        
            process.close();
    
            return a.exec();
    }
    

    The code above works fine. (At least, it does exactly what it is told to...)

    Here is the debug output:

    [dshow @ 0000019e7d4190c0] "OBS Virtual Camera" (video)
    [dshow @ 0000019e7d4190c0]   Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{A3FCE0F5-3493-419F-958A-ABA1250EC20B}"
    [dshow @ 0000019e7d4190c0] "Microphone (Realtek(R) Audio)" (audio)
    [dshow @ 0000019e7d4190c0]   Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{2409F2C8-F2CB-4A6D-AEA7-DAD79C4EE9DF}"
    dummy: Immediate exit requested
    

    There are two questions that I have about this:

    1- Currently, I use the readAllStandardError() method instead of the readAllStandardOutput() method, because the "dummy" argument in ffmpeg raises a Warning/Error. Is there a better alternative to this?

    2- The output generated by the above command does indeed list the devices, but I only need the audio devices. Furthermore, I need the format to be more friendly. Something similar to the following:

    "OBS Virtual Camera" (video)
    "Microphone (Realtek(R) Audio)" (audio)
     Other audio devices...
    

    So, I can retrieve them and put them in a QByteArray to show it in a GUI later on. Is there a better command to this that I am missing?

    (I am using a windows 11 machine for ffmpeg)

    B J 2 Replies Last reply 2 Mar 2023, 08:03
    0
    • S Saviz
      2 Mar 2023, 03:33

      I have some code that uses a QProcess object to call ffmpeg executable in the background to perform some tasks.

      In this case I am trying to obtain the list of audio input device names from ffmpeg.

      Code:

      #include <QApplication>
      #include <QDebug>
      #include <QProcess>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QProcess process;
          QStringList arguments;
           
          arguments
                    << "-hide_banner"
                    << "-nostats"
                    << "-list_devices"
                    << "true"
                    << "-f"
                    << "dshow"
                    << "-i"
                    << "dummy";
          
          
          
              process.start("Path/to/ffmpeg", arguments);
          
              process.waitForFinished();
          
              // I use standard error because the "dummy" argument seems to raise a warning/error
              QByteArray output = process.readAllStandardError();
          
          
              qDebug() << output;
          
              process.close();
      
              return a.exec();
      }
      

      The code above works fine. (At least, it does exactly what it is told to...)

      Here is the debug output:

      [dshow @ 0000019e7d4190c0] "OBS Virtual Camera" (video)
      [dshow @ 0000019e7d4190c0]   Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{A3FCE0F5-3493-419F-958A-ABA1250EC20B}"
      [dshow @ 0000019e7d4190c0] "Microphone (Realtek(R) Audio)" (audio)
      [dshow @ 0000019e7d4190c0]   Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{2409F2C8-F2CB-4A6D-AEA7-DAD79C4EE9DF}"
      dummy: Immediate exit requested
      

      There are two questions that I have about this:

      1- Currently, I use the readAllStandardError() method instead of the readAllStandardOutput() method, because the "dummy" argument in ffmpeg raises a Warning/Error. Is there a better alternative to this?

      2- The output generated by the above command does indeed list the devices, but I only need the audio devices. Furthermore, I need the format to be more friendly. Something similar to the following:

      "OBS Virtual Camera" (video)
      "Microphone (Realtek(R) Audio)" (audio)
       Other audio devices...
      

      So, I can retrieve them and put them in a QByteArray to show it in a GUI later on. Is there a better command to this that I am missing?

      (I am using a windows 11 machine for ffmpeg)

      B Offline
      B Offline
      Bonnie
      wrote on 2 Mar 2023, 08:03 last edited by Bonnie 3 Feb 2023, 08:31
      #2

      @Saviz Hey dear, this is not a ffmpeg related forum. You should find one and ask there if you want help about ffmpeg command.

      Ok, here's from what I know, there's no better command.
      If you want friendly output, just parse the text to read the names and write what you want to the GUI.

      *Note: The output of your audio devices contains both (video) and (audio) because that video device in the list can also be used as an audio input device. So I think we should keep that.

      1 Reply Last reply
      1
      • S Saviz
        2 Mar 2023, 03:33

        I have some code that uses a QProcess object to call ffmpeg executable in the background to perform some tasks.

        In this case I am trying to obtain the list of audio input device names from ffmpeg.

        Code:

        #include <QApplication>
        #include <QDebug>
        #include <QProcess>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            QProcess process;
            QStringList arguments;
             
            arguments
                      << "-hide_banner"
                      << "-nostats"
                      << "-list_devices"
                      << "true"
                      << "-f"
                      << "dshow"
                      << "-i"
                      << "dummy";
            
            
            
                process.start("Path/to/ffmpeg", arguments);
            
                process.waitForFinished();
            
                // I use standard error because the "dummy" argument seems to raise a warning/error
                QByteArray output = process.readAllStandardError();
            
            
                qDebug() << output;
            
                process.close();
        
                return a.exec();
        }
        

        The code above works fine. (At least, it does exactly what it is told to...)

        Here is the debug output:

        [dshow @ 0000019e7d4190c0] "OBS Virtual Camera" (video)
        [dshow @ 0000019e7d4190c0]   Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{A3FCE0F5-3493-419F-958A-ABA1250EC20B}"
        [dshow @ 0000019e7d4190c0] "Microphone (Realtek(R) Audio)" (audio)
        [dshow @ 0000019e7d4190c0]   Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{2409F2C8-F2CB-4A6D-AEA7-DAD79C4EE9DF}"
        dummy: Immediate exit requested
        

        There are two questions that I have about this:

        1- Currently, I use the readAllStandardError() method instead of the readAllStandardOutput() method, because the "dummy" argument in ffmpeg raises a Warning/Error. Is there a better alternative to this?

        2- The output generated by the above command does indeed list the devices, but I only need the audio devices. Furthermore, I need the format to be more friendly. Something similar to the following:

        "OBS Virtual Camera" (video)
        "Microphone (Realtek(R) Audio)" (audio)
         Other audio devices...
        

        So, I can retrieve them and put them in a QByteArray to show it in a GUI later on. Is there a better command to this that I am missing?

        (I am using a windows 11 machine for ffmpeg)

        J Offline
        J Offline
        JonB
        wrote on 2 Mar 2023, 08:07 last edited by
        #3

        @Saviz
        For the questions about what command line arguments you might want to pass to it you might be better asking in a forum for ffmpeg.

        When running a command whose output you are interested in you should always read both standard output and standard error.

        If you do not need to process them separately you might use QProcess::MergedChannels. But not if you need to parse them distinctly.

        If you want the output you show, and ffmpeg does not offer this, parse the output to produce what you want.

        1 Reply Last reply
        1

        2/3

        2 Mar 2023, 08:03

        • Login

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