PDA

View Full Version : Codec Detection


ipfreak
29th May 2002, 09:40
Hi all.

Does somebodfy know how to detect the
audio and video codecs installed on a machine.

Maybe display them in 2 seperate combo boxes.
One for audio and one for video.

Programming Language: Delphi 5 & 6

Thanks Chris

Swede
29th May 2002, 11:10
Maybe not the nicest way but you can do:
procedure TForm1.FormCreate(Sender: TObject);
var
Reg, Reg2: TRegistry;
sl: TStringList;
i: Integer;
begin
Reg:=TRegistry.Create;
Reg2:=TRegistry.Create;
sl:=TStringList.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg2.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32\')
and Reg2.OpenKeyReadOnly('\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers.desc\') then begin
Reg.GetValueNames(sl);
for i:=0 to sl.Count-1 do
if UpperCase(Copy(sl[i],1,4))='VIDC' then
vidc.Items.Add(Reg2.ReadString(Reg.ReadString(sl[i])))
else if UpperCase(Copy(sl[i],1,5))='MSACM' then
msacm.Items.Add(Reg2.ReadString(Reg.ReadString(sl[i])));
end;
Reg2.CloseKey;
Reg.CloseKey;
finally
sl.Free;
Reg2.Free;
Reg.Free;
end;
end;
Where, of course, vidc and msacm are two comboboxes or listboxes or whatever...

ipfreak
29th May 2002, 11:35
Chris

mario_a
10th June 2002, 12:19
Hi Swede,

Could u translate that into C++ for me?

Thanx a lot,
Mario

avih
10th June 2002, 15:39
on win xp:

control panel -> audio -> hardware -> audio codecs (or video codecs)
(in 98/me/2000 it's similar, but not exactly the same sequence described above)

this will give you all the codecs you can use in windows applications (i.e. vdub). it will not give you the dll's that are not installed into windows (such as the lame dll if some of your application uses it to compress to mp3).

BUT not everything is a codec (=coder/decoder). some are just decoders, such as mp3 decoder, mp2 a/v decoders, ffdshow (various mp4 decoders) etc.

these decoders are installed as direct show filters. to see all the direct show filters you can use graphedit and select 'insert filter', then click the '+' of 'DirectShow filters' and you'll see all the filters on your system (there can be quite a lot of them). clicking the '+' on each, will give you the file name and some more details.

instead of graphedit u can also use a small app called 'dxman' from analogx. it allows you to see all the info as in graphedit, but also lets you remove unwanted filters. get it from http://www.analogx.com/contents/download/audio.htm . you can also go to the main site, he has many other very cool small apps. all freeware.

cheers
avi.

[Toff]
10th June 2002, 18:28
Using C++ and DirectShow :


typedef std::vector<std::string> StringList;

clsidClass can be :
CLSID_VideoCompressorCategory
CLSID_AudioCompressorCategory
...

HRESULT InitList(StringList &sl, REFCLSID clsidClass)
{
// Initialize COM
CoInitialize(NULL);

// Clear list
sl.clear();

ICreateDevEnum *pSysDevEnum = NULL;
IEnumMoniker *pEnumCat = NULL;

// Create the System Device Enumerator.
m_hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
(void**)&pSysDevEnum);
CHECK_HRR(m_hr, "Can't create the System Device Enumerator.");

// Obtain a class enumerator for the provided device category.
m_hr = pSysDevEnum->CreateClassEnumerator(clsidDeviceClass, &pEnumCat, 0);
CHECK_HRR(m_hr, "Can't obtain a class enumerator for the provided device category.");

// Enumerate the monikers.
IMoniker *pMoniker = NULL;
ULONG cFetched;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pProp = NULL;
pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pProp);
VARIANT varName;
VariantInit(&varName); // Find the friendly name.
m_hr = pProp->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(m_hr))
{
char szName[64];
WideCharToMultiByte(CP_ACP, 0, varName.bstrVal, -1, szName, 64, 0, 0);
sl.push_back(szName);
}
VariantClear(&varName);
pProp->Release();
pProp = NULL;
pMoniker->Release();
pMoniker = NULL;
}

pSysDevEnum->Release();
pEnumCat->Release();

CoUninitialize();

return m_hr;
}

ex:
InitList(m_vAudioCodecList,CLSID_AudioCompressorCategory);

CHECK_HRR is a macro that check the result and display an error code.
You can your remove it.

gabest
11th June 2002, 05:36
And the ATL flavored version :p

HRESULT InitList(StringList &sl, REFCLSID clsidClass)
{
// Initialize COM
CoInitialize(NULL);

// Clear list
sl.clear();

CComPtr<ICreateDevEnum> pSysDevEnum;
CComPtr<IEnumMoniker> pEnumCat;

m_hr = pSysDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);
CHECK_HRR(m_hr, "Can't create the System Device Enumerator.");

// Obtain a class enumerator for the provided device category.
m_hr = pSysDevEnum->CreateClassEnumerator(clsidClass, &pEnumCat, 0);
CHECK_HRR(m_hr, "Can't obtain a class enumerator for the provided device category.");

// Enumerate the monikers.
for(CComPtr<IMoniker> pMoniker; pEnumCat->Next(1, &pMoniker, 0) == S_OK; pMoniker = NULL)
{
CComPtr<IPropertyBag> pProp;
pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pProp);

CComVariant varName;
m_hr = pProp->Read(L"FriendlyName", &varName, 0);
if(SUCCEEDED(m_hr))
{
char szName[64];
wcstombs(szName, varName.bstrVal, 64);
sl.push_back(szName);
}
}

CoUninitialize();

return m_hr;
}

mario_a
11th June 2002, 05:55
Thanx a lot to both Toff and Gabest.

Mario

avih
11th June 2002, 07:56
my apologies.
i didn't read the post correctly, and didn't notice it's in the 'development' section (was using 'view new posts'). i thought it was a general windows question.

oops
avi

Ocrana
13th June 2002, 18:39
Hello,

I think, search a codec is only good if you search via FourCC. Here is a sniplet from my prog where i look for the codecs my prog will work with.
If you look for every codec yo ucan set the FOurCC to NULL.

Ocrana



int i;
ICINFO icinfo;
HIC__ *hic;

int m=0;

CBEItem.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
CBEItem.cchTextMax = 0; // is ignored
CBEItem.iItem = -1; // insert at end

//Im Prinzip für jeden unterstützten Codec einen Scan durchführen.
//###############################################################
//DivXNetworks Scan
for (i=0; ICInfo(ICTYPE_VIDEO, i, &icinfo); i++)
{
hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_QUERY);
if (hic)
{
// Find out the compressor name.
ICGetInfo(hic, &icinfo, sizeof(ICINFO));
if(icinfo.fccHandler==mmioFOURCC( 'D','I','V','X'))
{
_totchar meincomp(icinfo.szDescription);
CBEItem.pszText = meincomp;
CBEItem.lParam = ( LPARAM )"c";
CBEItem.iSelectedImage =
CBEItem.iImage = 1; //
m_VideoCodecCombo.InsertItem(&CBEItem);
if(strstr(meincomp, "DivX 5.") || strstr(meincomp,"DivX Pro 5.")){
divx_n = 1;
} else {
divx_n = 2;
}

m=1;
ICClose(hic);
break;

}
ICClose(hic);
}
}

fragilerus
23rd July 2006, 23:04
does anybody know how to get this info in a simple batch file or autorun file? im trying to create a simple autorun file for a disc that should detect weather the codec is installed, and install it if it is not found