How to obtain list of audio input Devices with ffmpeg
-
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)
-
@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.
-
@Saviz
For the questions about what command line arguments you might want to pass to it you might be better asking in a forum forffmpeg
.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.