public void Open( string fileName )
{
// close previous file
Close( );
bool success = false;
try
{
lock ( sync )
{
// open AVI file
if ( Win32.AVIFileOpen( out file, fileName, Win32.OpenFileMode.ShareDenyWrite, IntPtr.Zero ) != 0 )
throw new System.IO.IOException( "Failed opening the specified AVI file." );
// get first video stream
if ( Win32.AVIFileGetStream( file, out stream, Win32.mmioFOURCC( "vids" ), 0 ) != 0 )
throw new VideoException( "Failed getting video stream." );
// get stream info
Win32.AVISTREAMINFO info = new Win32.AVISTREAMINFO( );
Win32.AVIStreamInfo( stream, ref info, Marshal.SizeOf( info ) );
width = info.rectFrame.right;
height = info.rectFrame.bottom;
position = info.start;
start = info.start;
length = info.length;
rate = (float) info.rate / (float) info.scale;
codec = Win32.decode_mmioFOURCC( info.handler );
// prepare decompressor
Win32.BITMAPINFOHEADER bitmapInfoHeader = new Win32.BITMAPINFOHEADER( );
bitmapInfoHeader.size = Marshal.SizeOf( bitmapInfoHeader.GetType( ) );
bitmapInfoHeader.width = width;
bitmapInfoHeader.height = height;
bitmapInfoHeader.planes = 1;
bitmapInfoHeader.bitCount = 24;
bitmapInfoHeader.compression = 0; // BI_RGB
// get frame object
if ( ( getFrame = Win32.AVIStreamGetFrameOpen( stream, ref bitmapInfoHeader ) ) == IntPtr.Zero )
{
bitmapInfoHeader.height = -height;
if ( ( getFrame = Win32.AVIStreamGetFrameOpen( stream, ref bitmapInfoHeader ) ) == IntPtr.Zero )
throw new VideoException( "Failed initializing decompressor." );
}
success = true;
}
}
finally
{
if ( !success )
{
Close( );
}
}
}