private static extern int AVIFileCreateStream( int ptr_pfile, out IntPtr ptr_ptr_avi, ref AVISTREAMINFOW ptr_streaminfo );
public static extern int AVIStreamInfo( int pAVIStream, ref AVISTREAMINFOW psi, int lSize );
private void CreateStream() { // video stream AVISTREAMINFOW strhdr = new AVISTREAMINFOW(); strhdr.fccType = _STREAM_TYPE_VIDEO; strhdr.fccHandler = 0;// fccHandler_; strhdr.dwFlags = 0; strhdr.dwCaps = 0; strhdr.wPriority = 0; strhdr.wLanguage = 0; strhdr.dwScale = m_scale; strhdr.dwRate = m_rate; strhdr.dwStart = 0; strhdr.dwLength = 0; strhdr.dwInitialFrames = 0; strhdr.dwSuggestedBufferSize = m_height * m_stride; strhdr.dwQuality = 0xffffffff; strhdr.dwSampleSize = 0; strhdr.rect_top = 0; strhdr.rect_left = 0; strhdr.rect_bottom = m_height; strhdr.rect_right = m_width; strhdr.dwEditCount = 0; strhdr.dwFormatChangeCount = 0; strhdr.szName0 = 0; strhdr.szName1 = 0; int hr = AVIFileCreateStream( m_file_handle, out m_video, ref strhdr ); if ( hr != 0 ) { throw new AviException( "AVIFileCreateStream; Video" ); } #if DEBUG Console.WriteLine( "AviWrierVfw+CreateStream" ); Console.WriteLine( " strhdr.fccHandler=" + strhdr.fccHandler ); #endif }
/// <summary> /// Opens an AVI file and creates a GetFrame object /// </summary> /// <param name="fileName">Name of the AVI file</param> public void Open( string fileName ) { //Intitialize AVI library VFW.AVIFileInit(); //Open the file int result = VFW.AVIFileOpenW( ref aviFile, fileName, (int)win32.OF_SHARE_DENY_WRITE, 0 ); if ( result != 0 ) { throw new Exception( "Exception in AVIFileOpen: " + result.ToString() ); } //Get the video stream result = VFW.AVIFileGetStream( aviFile, out aviStream, (int)VFW.streamtypeVIDEO, 0 ); if ( result != 0 ) { throw new Exception( "Exception in AVIFileGetStream: " + result.ToString() ); } firstFrame = VFW.AVIStreamStart( aviStream.ToInt32() ); countFrames = VFW.AVIStreamLength( aviStream.ToInt32() ); streamInfo = new AVISTREAMINFOW(); result = VFW.AVIStreamInfo( aviStream.ToInt32(), ref streamInfo, Marshal.SizeOf( streamInfo ) ); if ( result != 0 ) { throw new Exception( "Exception in AVIStreamInfo: " + result.ToString() ); } //Open frames BITMAPINFOHEADER bih = new BITMAPINFOHEADER(); bih.biBitCount = 24; bih.biClrImportant = 0; bih.biClrUsed = 0; bih.biCompression = 0; //BI_RGB; bih.biHeight = (Int32)streamInfo.rect_bottom; bih.biWidth = (Int32)streamInfo.rect_right; bih.biPlanes = 1; bih.biSize = (UInt32)Marshal.SizeOf( bih ); bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; getFrameObject = VFW.AVIStreamGetFrameOpen( aviStream, ref bih ); //force function to return 24bit DIBS //getFrameObject = Avi.AVIStreamGetFrameOpen(aviStream, 0); //return any bitmaps if ( getFrameObject == 0 ) { throw new Exception( "Exception in AVIStreamGetFrameOpen!" ); } m_opened = true; m_fileName = fileName; }