private void SetFormat(IntPtr aviStream)
{
Avi.BITMAPINFOHEADER bi = new Avi.BITMAPINFOHEADER();
bi.biSize = Marshal.SizeOf(bi);
bi.biWidth = width;
bi.biHeight = height;
bi.biPlanes = 1;
bi.biBitCount = countBitsPerPixel;
bi.biSizeImage = frameSize;
int result = Avi.AVIStreamSetFormat(aviStream, 0, ref bi, bi.biSize);
if(result != 0){ throw new Exception("Error in VideoStreamSetFormat: "+result.ToString()); }
}