[SOLUTION] Get List of available directshow devices(mingw)

For the developers that use FFmpeg in Windows software.

[SOLUTION] Get List of available directshow devices(mingw)

Postby bawki » Mon Jul 30, 2012 1:50 pm

I have been looking into the ffmpeg source code a few hours now and found some references to a list of directshow capturing devices. Is that list somehow accessible via the API?
When using an avdict with key list_devices = true it displays a list in console, but obviously i cannot access this.
I know vlc gets the list via the winapi so does ffmpeg internally but it would be nice to have access to that list via the ffmpeg api rather than using the windows api.
Last edited by bawki on Mon Jul 30, 2012 8:52 pm, edited 1 time in total.
bawki
 
Posts: 3
Joined: Mon Jul 30, 2012 1:45 pm

Re: Get List of available directshow devices

Postby rogerdpack » Mon Jul 30, 2012 3:36 pm

a couple things to come to mind:
if you have access to an ffmpeg.exe, you could just run it and "parse" the command line output.
if you don't, you could just copy and paste that code into your program and run it.
I have no idea what constitutes "ok" and "not ok" public api's for the main dev's you'd probably have to ask them (ffmpeg-devel list).
rogerdpack
 
Posts: 1454
Joined: Fri Aug 05, 2011 9:56 pm

Re: Get List of available directshow devices

Postby bawki » Mon Jul 30, 2012 8:12 pm

fixed in next post.
Last edited by bawki on Mon Jul 30, 2012 8:51 pm, edited 1 time in total.
bawki
 
Posts: 3
Joined: Mon Jul 30, 2012 1:45 pm

Re: Get List of available directshow devices

Postby bawki » Mon Jul 30, 2012 8:50 pm

works with mingw and qt4 :)


winsdk.pri:
Code: Select all
win32: {
    LIBS += -lStrmiids -lQuartz -lole32 -luuid -loleaut32
}

include that in your .pro file with include(winsdk.pri)

header file(where you want to use ffmpeg):
Code: Select all
DEFINE_GUID(CLSID_VideoInputDeviceCategory,0x860bb310,0x5d01,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86);


cpp file:
Code: Select all
void listDevices()
{
    QList<QString> deviceNames;
    ICreateDevEnum *pDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum,0,CLSCTX_INPROC_SERVER,IID_ICreateDevEnum,(void**)&pDevEnum);
    if(FAILED(hr))
        return;
    IEnumMoniker *pEnum;
    hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEnum,0);
    if(FAILED(hr))
    {
        return;
    }
    IMoniker *pMoniker = NULL;
    while(S_OK == pEnum->Next(1,&pMoniker,NULL))
    {
        IPropertyBag *pPropBag;
        LPOLESTR str = 0;
        hr = pMoniker->GetDisplayName(0,0,&str);
        if(SUCCEEDED(hr))
        {
            hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pPropBag);
            if(SUCCEEDED(hr))
            {
                VARIANT var;
                VariantInit(&var);
                hr = pPropBag->Read(L"FriendlyName",&var,0);
                QString fName = QString::fromWCharArray(var.bstrVal);
                deviceNames.append(fName);
            } else {
                qDebug() << "could not bind to storage";
            }
        }
    }
    if(deviceNames.size()>0)
    {
// I am using a QComboBox to list the devices, you can just use the QList<QString> deviceNames for your purpose
        ui->deviceListBox->addItems(deviceNames);
    }
}

void openInput()
{
        AVFormatContext *formatC = avformat_alloc_context();
        AVInputFormat *iformat = av_find_input_format("dshow");
        if(iformat)
        {
            qDebug() << "name: " << iformat->name;
            qDebug() << "device name: " << ui->deviceListBox->currentText().toAscii().constData();
            QString devName = "video=";
            devName += ui->deviceListBox->currentText();
            if(avformat_open_input(&formatC,devName.toAscii().constData(),iformat,NULL)!=0)
            {
                qDebug() << "could not open!";
                return;
            } else {
                qDebug() << "opened :D";
                qDebug() << "streams: " << formatC->nb_streams;
            }
        } else
            qDebug() << "no iformat";
}
bawki
 
Posts: 3
Joined: Mon Jul 30, 2012 1:45 pm

Re: [SOLUTION] Get List of available directshow devices(ming

Postby rogerdpack » Mon Jul 30, 2012 9:47 pm

nice, thanks for the snippet.
rogerdpack
 
Posts: 1454
Joined: Fri Aug 05, 2011 9:56 pm

Re: [SOLUTION] Get List of available directshow devices(ming

Postby rogerdpack » Tue Nov 13, 2012 6:45 pm

https://gist.github.com/3210277 may also be related (how to enumerate dshow devices)

also viewtopic.php?f=15&t=856&p=3294&hilit=ruby#p3291 has a link to demo ruby code I use to parse ffmpeg's stdout.
rogerdpack
 
Posts: 1454
Joined: Fri Aug 05, 2011 9:56 pm


Return to Using FFmpeg In Windows Software

Who is online

Users browsing this forum: Bing [Bot] and 3 guests