Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AMCap to C#

421 views
Skip to first unread message

Kevin Tupper

unread,
Sep 17, 2002, 12:19:34 AM9/17/02
to
I need a very simple progam to capture AVI file in DV format from a 1394
firewire card. I need to control it via .Net remoting.

The program should read from a config file for it's device settings and
simply capture using DV format to a specified file. The client program will
tell it START with a file name to capture to and STOP.

The features in the AMCap program work perfectly and I'm able to capture
with it just fine.

Unfortunately it's in C++ which I'm unfamiliar with for the most part. I've
just started doing C# programming having come from the Delphi world.

Is it easy to convert AMCap to C#? Does anyone know of any Active-X or Com
controls that work to capture DV and can be called from C#? (I've tried
several that don't work)

For an experienced programmer, what type of charge would there be to convert
AMCap to work in C#?

Thanks,

Kevin


The March Hare

unread,
Sep 17, 2002, 12:32:54 AM9/17/02
to
DirectShow does not offer much support for C#. For further information I
recommend you search the Google Groups archives on this topic in this
newsgroup. The question has been asked a number of times before. I
believe there is even some information from some MS folks on what DirectX C#
support will be offered in DX9. I can't comment any further because I'm
under a NDA for DX9 beta.

The simple answer is learn C++ if you really want to take advantage of
DirectShow.

"Kevin Tupper" <tuppe...@hotmail.com> wrote in message
news:uzEBuEgXCHA.1748@tkmsftngp09...

Claudio Serrano

unread,
Sep 18, 2002, 11:25:36 AM9/18/02
to
im sending you a few lines of c# code to ilustrate how you
could do it with c#, itis not the whole project because
its a private project and we arent selling it. but i hope
this could help you to learn how to doit by yourself

internal class DigitalCam : WebCam
{
private int hWnd = 0 ;
private Timer timer;

[DllImport("avicap32.dll")]
private static extern int
capCreateCaptureWindow(string a, int b, int c, int d, int
e, int f, int g, int h);

[DllImport("user32.dll")]
private static extern int SendMessage(int
hWnd, int wMsg, int wParam, int lParam);

[DllImport("user32.dll",
EntryPoint="SendMessageA")]
private static extern int SendMessageS(int
hWnd, int wMsg, int wParam, string lParam);


[DllImport("user32.dll")]
private static extern int GetDesktopWindow
();

[DllImport("user32.dll")]



private static extern int DestroyWindow
(int hWnd);

public void StartPreview(int handle)
{

int hWnd = capCreateCaptureWindow
("Analog Cam", (int)
VideoConstants.ws_child,0,0,320,240,handle,0);
if (hWnd == 0)
throw new
ApplicationException("Error getting Desktop Window");

int temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq_nofile,0,0);


temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_driver_connect,1,0);
if (temp == 0)
throw new
ApplicationException("Error connecting to driver");



}

unsafe public void StartVideo()
{
int desktopWnd = 0;
desktopWnd = GetDesktopWindow();


CAPTUREPARAMS param;

if (desktopWnd == 0)
throw new
ApplicationException("Error getting Desktop Window");
hWnd = capCreateCaptureWindow
("Analog Cam", (int)
VideoConstants.ws_child,0,0,0,0,desktopWnd,0);
if (hWnd == 0)
throw new
ApplicationException("Error getting Desktop Window");


int temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);

//Video AVI
param.fYield = 1;

int totalFrame = 25;
param.dwRequestMicroSecPerFrame=
1000000 / totalFrame;

param.fCaptureAudio = 0;

temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_SET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq_nofile,0,0);

int algo = sizeof(CAPTUREPARAMS);
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_set_previewrate,4,0);
if (temp == 0)
throw new
ApplicationException("Error Setting Preview Rate");


temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_driver_connect,1,0);
if (temp == 0)
throw new
ApplicationException("Error connecting to driver");

}

unsafe public void SaveAvi(string name)
{
CAPTUREPARAMS param;
int temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);

param.fYield = 1;

int totalFrame = 25;
param.dwRequestMicroSecPerFrame=
1000000 / totalFrame;
param.fAbortLeftMouse=0;
param.fAbortRightMouse=0;
param.fCaptureAudio = 0;
param.fLimitEnabled=0;
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_SET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);


temp = SendMessageS(hWnd,(int)
VideoConstants.WM_CAP_FILE_SET_CAPTURE_FILE,0,name);
if (temp == 0)
throw new
ApplicationException("Error setting file name");
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq,0,0);
if (temp == 0)
throw new
ApplicationException("Error saving avi to disk");
}


unsafe public void SaveAvi(string name,
int seconds, object state)
{

CAPTUREPARAMS param;
int temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);

param.fYield = 1;

int totalFrame = 25;
param.dwRequestMicroSecPerFrame=
1000000 / totalFrame;
param.fAbortLeftMouse=0;
param.fAbortRightMouse=0;
param.fCaptureAudio = 0;
param.fLimitEnabled=1;
param.wTimeLimit=(uint)seconds;
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_SET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)&param);


temp = SendMessageS(hWnd,(int)
VideoConstants.WM_CAP_FILE_SET_CAPTURE_FILE,0,name);
if (temp == 0)
throw new
ApplicationException("Error setting file name");
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq,0,0);

timer = new Timer(new TimerCallback
(myStopAvi),state,seconds*1000,Timeout.Infinite);


/*if (temp == 0)
throw new
ApplicationException("Error saving avi to disk");*/
}

private void myStopAvi(object state)
{
Hashtable table = state as
Hashtable;
lock(table)
{
table["Flag"] = false;
}

}

public void StopAvi()
{
int temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_stop,0,0);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq_nofile,0,0);

}
public void CloseVideo()
{
int temp = SendMessage(hWnd, (int)
VideoConstants.wm_cap_driver_disconnect, 0, 0);
temp = DestroyWindow (hWnd);
}

public byte[] GrabFrame(int width, int
height, int resolution)
{
//int temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_grab_frame,0,0);
int temp = SendMessageS(hWnd,(int)
VideoConstants.wm_cab_grab_frame_nonstop,0,"smartpicture.bm
p");
if (temp == 0)
{
throw new
ApplicationException("Error in Grab frame no stop");

}

if (temp == 0)
throw new
ApplicationException("Error Setting Grab Frame");

temp = SendMessageS(hWnd,(int)
VideoConstants.wm_cap_file_savedib,0,"smartpicture.bmp");
if (temp == 0)
{
throw new
ApplicationException("Error saving bitmap to disk");

}


FileStream f = new FileStream
("smartpicture.bmp", FileMode.OpenOrCreate);
byte [] buffer = new byte
[f.Length];
f.Read(buffer,0,buffer.Length);
f.Close();
return buffer;

}
}
}

>-----Original Message-----
>Message unavailable

Thomas Tomiczek [MVP]

unread,
Sep 19, 2002, 3:57:24 AM9/19/02
to
You deffinitly win a price or using outdated API's. Seriously. Looks like
Video For Windows to me, which is deprecated and outdated since a lot of
years :-)

Ever thought of using DirectShow? And using the COM interface to it? Once
you want to make a little more than what you do (for example adding other
filters etc.) ou are in for a nasty surprise.

--
Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

"Claudio Serrano" <claudio...@hotmail.com> wrote in message
news:1cd201c25f27$a2d4e620$36ef2ecf@tkmsftngxa12...

0 new messages