Capturing AVI's in D3

I'm trying to write an app that'll capture avi's.

So far, I've tried playing about with avicap.dll and can get basic capture.

What I can't do, however, is set the compression codec programatically.

You can get a dialogue up for the user to set it (WM_USER + 46), but my app
needs to capture lots of clips unattended..

Is there a better way of capturing??