Click here to Skip to main content
15,902,198 members
Articles / Desktop Programming / MFC
Article

Capture Live Video from various Video Devices.

Rate me:
Please Sign up or sign in to vote.
4.72/5 (62 votes)
20 May 2004CPOL2 min read 757.1K   45.1K   206   201
LiveVideo is an application to capture live video from various video capture devices.

Sample Image - LiveVideo.jpg

Introduction

This is an attempt to create an application which captures Live video from a Video capture device and USB attached WebCam all together in the same application. While developing my project, I needed to capture the video from various video devices including TV. Though, I found some source for capturing Video, it was not so efficient. So, that prompted me to develop my own independent application. Initially, “LiveVideo” detects the availability of the Video Capture card and whether WebCam is attached or not. Otherwise, it shows the message. Most of the API functions are used from DirectX SDK.

Steps to Use

  • Create a Dialog based application.
  • Insert a Picture control of size 320x240 pixel.
  • In the properties of the Picture control, set TYPE as ‘Rectangle’ and COLOR as ‘Black’.
  • Add the files “CaptureVideo.cpp” and “CaptureDevice.h” to your project.
  • Add “CaptureVide.h” into your implementation header file.
  • Create an Object of the class “CCaptureVideo” using Class wizard.
  • Link the libraries strmbasd.lib, wmvcore.lib, wmstub.lib in your project settings.

Now, using the object, invoke InitializeVideo(HWND hWnd) function to initialize the video.

HRESULT hr = capVideo.InitializeVideo(hWnd);

Where hWnd is the window handle of the picture control.

  • StartSVideo() - To start capturing from SVideo.
  • StartCompositeVideo() - To start capturing from Composite Video.
  • StartTVTuner() - To start capturing from TVTuner.
  • StartWebcam() - To start capturing from WebCam.

Important:

Don’t forget to uninitialize the Video by using UnInitializeVideo() before destroying your application.

Requirements:

  • Video Capture card. I’ve tested with “WinFast TV2000 XP WDM Video Capture” card. Hope it will work with all video capture cards.
  • USB Cam.
  • You need to install DirectX, which is available freely from Microsoft. You can download DirectX 9.0 from Microsoft.
  • For development, install DirectX 9.0 SDK. You can download DirectX 9.0 SDK from Microsoft.

Conclusion

I hope this article is of some use to you. I would add Configuration settings of the Video features and Video quality in my next version. Feel free to use these classes as you like. Any comments or improvements would be appreciated.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Hi Friends.,

I am DILLIP working as a Software Engineer in South Korea .

My Hobbies:

Listening to Music, Net Browsing , watching TV..

Comments and Discussions

 
GeneralRe: dshow.h Pin
dillian wong19-Nov-09 17:36
dillian wong19-Nov-09 17:36 
QuestionHow to create an object? Pin
avogadro626-Sep-05 6:16
avogadro626-Sep-05 6:16 
Generalplease , i have an error in dshow.h Pin
dynamica12330-Aug-05 3:21
dynamica12330-Aug-05 3:21 
GeneralRe: please , i have an error in dshow.h Pin
dillian wong19-Nov-09 17:38
dillian wong19-Nov-09 17:38 
GeneralISampleGrabber Pin
Brooks Y.14-Aug-05 6:21
Brooks Y.14-Aug-05 6:21 
GeneralRe: ISampleGrabber Pin
Brooks Y.15-Aug-05 1:48
Brooks Y.15-Aug-05 1:48 
GeneralSave video to WMV file Pin
cla795-Aug-05 22:42
cla795-Aug-05 22:42 
GeneralRe: Save video to WMV file Pin
khkh11-Aug-05 2:15
khkh11-Aug-05 2:15 
The easiest way to build this graph is by specifing MEDIASUBTYPE_Asf in the ICaptureGraphBuilder2::SetOutputFileName method:

IBaseFilter* pASFWriter = 0;
hr = pBuild->SetOutputFileName(
&MEDIASUBTYPE_Asf, // Create a Windows Media file.
L"C:\\VidCap.wmv", // File name.
&pASFWriter, // Receives a pointer to the filter.
NULL); // Receives an IFileSinkFilter interface pointer (optional).

The value MEDIASUBTYPE_Asf tells the Capture Graph Builder to use the WM ASF Writer filter as the file sink. The Capture Graph Builder creates the filter, adds it to the graph, and calls IFileSinkFilter::SetFileName to set the name of the output file. It returns a pointer to the filter as an outgoing parameter (pASFWriter in the previous example).

Use the IConfigAsfWriter interface on the WM ASF Writer to set the Windows Media profile. You must do this before you connect any pins on the WM ASF Writer.

IConfigAsfWriter *pConfig = 0;
hr = pASFWriter->QueryInterface(IID_IConfigAsfWriter, (void**)&pConfig);
if (SUCCEEDED(hr))
{
// Configure the ASF Writer filter.
pConfig->Release();
}

For more information about setting the profile, see Creating ASF Files in DirectShow.

Call ICaptureGraphBuilder2::RenderStream to connect the capture filter to the ASF Writer:

hr = pBuild->RenderStream(
&PIN_CATEGORY_CAPTURE, // Capture pin.
&MEDIATYPE_Video, // Video. Use MEDIATYPE_Audio for audio.
pCap, // Pointer to the capture filter.
0,
pASFWriter); // Pointer to the sink filter (ASF Writer).

Each input pin on the WM ASF Writer filter corresponds to a stream in the Windows Media profile. You must connect every pin, so that the file content matches the profile.

Generalplease , i need dshow.h Pin
dynamica12330-Jul-05 1:32
dynamica12330-Jul-05 1:32 
GeneralRe: please , i need dshow.h Pin
Anonymous3-Aug-05 23:28
Anonymous3-Aug-05 23:28 
GeneralVideo size Pin
khkh21-Jul-05 0:27
khkh21-Jul-05 0:27 
GeneralCan't find all "file.h" in MVS Pin
cyril82617-Jun-05 2:22
cyril82617-Jun-05 2:22 
GeneralCan't find dshow.h Pin
elvis89002-Jun-05 15:09
elvis89002-Jun-05 15:09 
GeneralRe: Can't find dshow.h Pin
Christian Graus2-Jun-05 16:27
protectorChristian Graus2-Jun-05 16:27 
GeneralRe: Can't find dshow.h Pin
User 223702-Jun-05 19:08
User 223702-Jun-05 19:08 
GeneralRe: Can't find dshow.h Pin
elvis89003-Jun-05 12:24
elvis89003-Jun-05 12:24 
GeneralRe: Can't find dshow.h Pin
Ștefan-Mihai MOGA17-Mar-06 3:05
professionalȘtefan-Mihai MOGA17-Mar-06 3:05 
GeneralQuestion Pin
Rene Pally31-May-05 5:59
Rene Pally31-May-05 5:59 
GeneralCallback function Pin
mattglennen24-May-05 5:17
mattglennen24-May-05 5:17 
GeneralError when compiling Pin
Mustang6818-May-05 13:32
Mustang6818-May-05 13:32 
GeneralRe: Error when compiling Pin
JeanMoul11-Jun-05 2:08
JeanMoul11-Jun-05 2:08 
GeneralRe: Error when compiling Pin
shayirli15-Jun-05 1:57
shayirli15-Jun-05 1:57 
GeneralRe: Error when compiling Pin
upadrino2-Nov-05 10:53
upadrino2-Nov-05 10:53 
GeneralRe: Error when compiling Pin
dillian wong19-Nov-09 17:44
dillian wong19-Nov-09 17:44 
GeneralRe: Error when compiling Pin
avogadro626-Sep-05 3:35
avogadro626-Sep-05 3:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.