Inheritance: IAviWriter
Ejemplo n.º 1
0
        unsafe public static AVICOMPRESSOPTIONS RequireVideoCompressOption(AVICOMPRESSOPTIONS current_option)
        {
            AviWriterVfw temp = new AviWriterVfw();

            temp.m_scale = 1000;
            temp.m_rate  = 30 * temp.m_scale;
            int width = 10, height = 10;

            temp.m_width  = (UInt32)width;
            temp.m_height = (UInt32)height;
            using (Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb)) {
                BitmapData bmpDat = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                temp.m_stride = (UInt32)bmpDat.Stride;
                bmp.UnlockBits(bmpDat);
            }
            AVIFileInit();
            string temp_file = Path.GetTempFileName() + ".avi";// .aviを付けないと、AVIFileOpenWが失敗する
            int    hr        = AVIFileOpenW(ref temp.m_file_handle, temp_file, OF_WRITE | OF_CREATE, 0);

            if (hr != 0)
            {
                throw new AviException("error for AVIFileOpenW");
            }

            temp.CreateStream();

            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();

            opts.fccType           = 0; //fccType_;
            opts.fccHandler        = 0; //fccHandler_;
            opts.dwKeyFrameEvery   = 0;
            opts.dwQuality         = 0; // 0 .. 10000
            opts.dwFlags           = 0; // AVICOMRPESSF_KEYFRAMES = 4
            opts.dwBytesPerSecond  = 0;
            opts.lpFormat          = new IntPtr(0);
            opts.cbFormat          = 0;
            opts.lpParms           = new IntPtr(0);
            opts.cbParms           = 0;
            opts.dwInterleaveEvery = 0;

            opts = current_option;
            AVICOMPRESSOPTIONS * p  = &opts;
            AVICOMPRESSOPTIONS **pp = &p;
            IntPtr  x      = temp.m_video;
            IntPtr *ptr_ps = &x;

            AVISaveOptions(IntPtr.Zero, 0, 1, ptr_ps, pp);
            //MessageBox.Show( "AVISaveOptions ok" );
            AVICOMPRESSOPTIONS copied = new AVICOMPRESSOPTIONS();

            copied = opts;
            AVIStreamRelease(temp.m_video);
            //MessageBox.Show( "AVIStreamRelease(temp.m_video) ok" );

            AVIFileRelease(temp.m_file_handle);
            //MessageBox.Show( "AVIFileRelease ok" );
            AVIFileExit();
            //MessageBox.Show( "AVIFileExit ok" );
            File.Delete(temp_file);
            //MessageBox.Show( "File.Delete(fileName) ok" );
            return(copied);
        }
Ejemplo n.º 2
0
        unsafe public static AVICOMPRESSOPTIONS RequireVideoCompressOption( AVICOMPRESSOPTIONS current_option ) {
            AviWriterVfw temp = new AviWriterVfw();
            temp.m_scale = 1000;
            temp.m_rate = 30 * temp.m_scale;
            int width = 10, height = 10;
            temp.m_width = (UInt32)width;
            temp.m_height = (UInt32)height;
            using ( Bitmap bmp = new Bitmap( width, height, PixelFormat.Format24bppRgb ) ) {
                BitmapData bmpDat = bmp.LockBits( new Rectangle( 0, 0, width, height ), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb );
                temp.m_stride = (UInt32)bmpDat.Stride;
                bmp.UnlockBits( bmpDat );
            }
            AVIFileInit();
            string temp_file = Path.GetTempFileName() + ".avi";// .aviを付けないと、AVIFileOpenWが失敗する
            int hr = AVIFileOpenW( ref temp.m_file_handle, temp_file, OF_WRITE | OF_CREATE, 0 );
            if ( hr != 0 ) {
                throw new AviException( "error for AVIFileOpenW" );
            }

            temp.CreateStream();

            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();
            opts.fccType = 0; //fccType_;
            opts.fccHandler = 0;//fccHandler_;
            opts.dwKeyFrameEvery = 0;
            opts.dwQuality = 0;  // 0 .. 10000
            opts.dwFlags = 0;  // AVICOMRPESSF_KEYFRAMES = 4
            opts.dwBytesPerSecond = 0;
            opts.lpFormat = new IntPtr( 0 );
            opts.cbFormat = 0;
            opts.lpParms = new IntPtr( 0 );
            opts.cbParms = 0;
            opts.dwInterleaveEvery = 0;

            opts = current_option;
            AVICOMPRESSOPTIONS* p = &opts;
            AVICOMPRESSOPTIONS** pp = &p;
            IntPtr x = temp.m_video;
            IntPtr* ptr_ps = &x;
            AVISaveOptions( IntPtr.Zero, 0, 1, ptr_ps, pp );
            //MessageBox.Show( "AVISaveOptions ok" );
            AVICOMPRESSOPTIONS copied = new AVICOMPRESSOPTIONS();
            copied = opts;
            AVIStreamRelease( temp.m_video );
            //MessageBox.Show( "AVIStreamRelease(temp.m_video) ok" );

            AVIFileRelease( temp.m_file_handle );
            //MessageBox.Show( "AVIFileRelease ok" );
            AVIFileExit();
            //MessageBox.Show( "AVIFileExit ok" );
            File.Delete( temp_file );
            //MessageBox.Show( "File.Delete(fileName) ok" );
            return copied;
        }