Did that help at all? What parts need clarification?
Main Topics
Browse All TopicsHi There,
My question is simple actually. Using the microsoft DirectX SDK 8.1 and 9.0 (AmCap etc.) Visual C++ samples I am able to preview and capture video from a webcam to a uncompressed video format, but these files are HUGE. All I want to do is preview the video while saving it to a compressed video format in an WMV or AVI file.
I have tried combining DirectX preview with ASF writer functions, but the graph always failed whatever profiles I used. Uncompressed it works in AVI format (AMCap sample)
Did anybody solve this problem? Any C++ solution (preferably with a little source code) that saves webcam live video into a compressed video format is welcome.
(I'm using both Visual Studio 6 and .net 2003)
Greetings,
inekedg@hotmail.com
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Dear,
Perhaps you might find the article at: http://www.geocities.com/k
Thanking you,
Yours,
P.GopalaKrishna.
Business Accounts
Answer for Membership
by: _corey_Posted on 2003-10-06 at 11:58:15ID: 9500200
Here is some sample code of one way to do it with manual pin connections:
hwnd)
2 , NULL, CLSCTX_INPROC, (void **) &g_pCapture);
ID_IMediaC ontrol,(LP VOID *) &g_pMC2);
ID_IVideoW indow, (LPVOID *) &g_pVW);
SystemDevi ceEnum, NULL, CLSCTX_INPROC,
umerator(C LSID_Video InputDevic eCategory, &pClassEnum, 0)!=S_OK)
umerator(C LSID_Video Compressor Category, &pClassEnum2, 0)!=S_OK)
umerator(C LSID_Legac yAmFilterC ategory, &pClassEnum3, 0)!=S_OK)
0, IID_IPropertyBag, ame", &var, 0); trVal,4)) L,NULL,IID _IBaseFilt er,(void** )&bf2);
0, IID_IPropertyBag, ame", &var, 0); L,NULL,IID _IBaseFilt er,(void** )&bf3);
L,NULL,IID _IBaseFilt er,(void** )&bf4);
orMoniker( pMoniker,0 ,L"Vid Source",&pVC);
compressio n filter"); smart tee filter"); video render filter");
(g_pGraph) ;
&PIN_CATEG ORY_CAPTUR E,&MEDIATY PE_Video,p VC,NULL,&t val,NULL,N ULL);
ame(&MEDIA SUBTYPE_Av i,L"C:\\OC U\\OCU\\te st.avi",&p Mux,&fsf);
in, smartIpin); n1,compIpi n); , muxIpin); n2, videorIpin);
wnd);
CHILD | WS_CLIPCHILDREN);
, 0, rc.right, rc.bottom);
;
HWND)hwnd, WM_GRAPHNOTIFY, 0);
//Video Setup code for capture
HRESULT InitCaptureInterfaces(HWND
{
HRESULT hr;
IEnumMoniker *pClassEnum2 = NULL;
IEnumMoniker *pClassEnum3 = NULL;
//IEnumMoniker *pClassEnum = NULL;
CComPtr<IEnumMoniker> pClassEnum = NULL;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// Create the filter graph
hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IFilterGraph2, (void **) &g_pGraph);
if (FAILED(hr))
return hr;
// Create the capture graph builder
hr = CoCreateInstance (CLSID_CaptureGraphBuilder
IID_ICaptureGraphBuilder2,
if (FAILED(hr))
return hr;
// Obtain interfaces for media control and Video Window
hr = g_pGraph->QueryInterface(I
if (FAILED(hr))
return hr;
hr = g_pGraph->QueryInterface(I
if (FAILED(hr))
return hr;
// Create the system device enumerator.
ICreateDevEnum *pDevEnum = NULL;
if(CoCreateInstance(CLSID_
IID_ICreateDevEnum, (void **)&pDevEnum) != S_OK)
{
return E_FAIL;
}
// Create an enumerator for video capture devices.
if(pDevEnum->CreateClassEn
{
return E_FAIL;
}
if(pDevEnum->CreateClassEn
{
return E_FAIL;
}
if(pDevEnum->CreateClassEn
{
return E_FAIL;
}
ULONG cFetched;
IMoniker *pMoniker = NULL;
while (pClassEnum2->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag = NULL;
pMoniker->BindToStorage(0,
(void **)&pPropBag);
VARIANT var;
VariantInit(&var);
pPropBag->Read(L"FriendlyN
if (SUCCEEDED(hr))
{
if(!wcsncmp(L"DivX",var.bs
{
pMoniker->BindToObject(NUL
}
}
pPropBag->Release();
VariantClear(&var);
pMoniker->Release();
}
pClassEnum2->Release();
while (pClassEnum3->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag = NULL;
pMoniker->BindToStorage(0,
(void **)&pPropBag);
VARIANT var;
VariantInit(&var);
pPropBag->Read(L"FriendlyN
if (SUCCEEDED(hr))
{
if(!wcscmp(L"Smart Tee",var.bstrVal) && (bf3 == NULL))
{
pMoniker->BindToObject(NUL
}
if(!wcscmp(L"Video Renderer",var.bstrVal) && (bf4 == NULL))
{
pMoniker->BindToObject(NUL
}
}
pPropBag->Release();
VariantClear(&var);
pMoniker->Release();
}
pClassEnum3->Release();
if (pClassEnum->Next(1, &pMoniker, &cFetched) == S_OK)
{
hr = g_pGraph->AddSourceFilterF
if (FAILED(hr))
return hr;
pMoniker->Release();
}
else
return E_FAIL;
pClassEnum = NULL;
g_pGraph->AddFilter(bf2,L"
g_pGraph->AddFilter(bf3,L"
g_pGraph->AddFilter(bf4,L"
hr = g_pCapture->SetFiltergraph
if (FAILED(hr))
return hr;
__int64 tval=0xFFFFFFFFFFFFFFFF;
hr = g_pCapture->ControlStream(
if (FAILED(hr))
return hr;
hr = g_pCapture->SetOutputFileN
if (FAILED(hr))
return hr;
sourceOpin = GetOutPin(pVC,0);
compIpin = GetInPin(bf2,0);
compOpin = GetOutPin(bf2,0);
muxIpin = GetInPin(pMux,0);
smartIpin = GetInPin(bf3,0);
smartOpin1 = GetOutPin(bf3,0);
smartOpin2 = GetOutPin(bf3,1);
videorIpin = GetInPin(bf4,0);
hr = g_pGraph->Connect(sourceOp
if (FAILED(hr))
return hr;
hr = g_pGraph->Connect(smartOpi
if (FAILED(hr))
return hr;
hr = g_pGraph->Connect(compOpin
if (FAILED(hr))
return hr;
hr = g_pGraph->Connect(smartOpi
if (FAILED(hr))
return hr;
hr = g_pVW->put_Owner((OAHWND)h
if (FAILED(hr))
return hr;
// Set video window style
hr = g_pVW->put_WindowStyle(WS_
if (FAILED(hr))
return hr;
// Use helper function to position video window in client rect
// of main application window
if (g_pVW)
{
RECT rc;
// Make the preview video fill our window
::GetClientRect(hwnd, &rc);
hr = g_pVW->SetWindowPosition(0
if (FAILED(hr))
return hr;
}
// Make the video window visible, now that it is properly positioned
hr = g_pVW->put_Visible(OATRUE)
if (FAILED(hr))
return hr;
// Set the window handle used to process graph events
// hr = g_pME->SetNotifyWindow((OA
// if (FAILED(hr))
// return hr;
hr = g_pMC2->Run();
return hr;
}