Example #1
0
        /// <summary>
        /// Method to set the video options.
        /// </summary>
        unsafe private void SetOptions()
        {
            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();

            opts.fccType           = 0;
            opts.fccHandler        = 0;
            opts.dwKeyFrameEvery   = 0;
            opts.dwQuality         = 0;
            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;

            AVICOMPRESSOPTIONS * p  = &opts;
            AVICOMPRESSOPTIONS **pp = &p;

            IntPtr  x      = m_ps;
            IntPtr *ptr_ps = &x;

            // Need to study the best way for setting the options.
            // AVISaveOptions(0, 0, 1, ptr_ps, pp);

            int hr = AVIMakeCompressedStream(out m_psCompressed,
                                             m_ps,
                                             ref opts,
                                             0);

            if (hr != 0)
            {
                throw new AviException("Err: AVIMakeCompressedStream");
            }

            BITMAPINFOHEADER bi = new BITMAPINFOHEADER();

            bi.biSize          = 40;
            bi.biWidth         = (int)m_width;
            bi.biHeight        = (int)m_height;
            bi.biPlanes        = 1;
            bi.biBitCount      = 24;
            bi.biCompression   = 0; // 0 = BI_RGB
            bi.biSizeImage     = m_stride * m_height;
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed       = 0;
            bi.biClrImportant  = 0;

            hr = AVIStreamSetFormat(m_psCompressed,
                                    0,
                                    ref bi,
                                    40);

            if (hr != 0)
            {
                throw new AviException("Err: AVIStreamSetFormat", hr);
            }
        }
Example #2
0
    unsafe private void SetOptions()
    {
        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;

        AVICOMPRESSOPTIONS * p  = &opts;
        AVICOMPRESSOPTIONS **pp = &p;

        IntPtr  x      = ps_;
        IntPtr *ptr_ps = &x;

        AVISaveOptions(0, 0, 1, ptr_ps, pp);



        // TODO: AVISaveOptionsFree(...)

        int hr = AVIMakeCompressedStream(out psCompressed_, ps_, ref opts, 0);

        if (hr != 0)
        {
            throw new AviException("AVIMakeCompressedStream");
        }

        BITMAPINFOHEADER bi = new BITMAPINFOHEADER();

        bi.biSize          = 40;
        bi.biWidth         = (Int32)width_;
        bi.biHeight        = (Int32)height_;
        bi.biPlanes        = 1;
        bi.biBitCount      = 24;
        bi.biCompression   = 0; // 0 = BI_RGB
        bi.biSizeImage     = stride_ * height_;
        bi.biXPelsPerMeter = 0;
        bi.biYPelsPerMeter = 0;
        bi.biClrUsed       = 0;
        bi.biClrImportant  = 0;

        hr = AVIStreamSetFormat(psCompressed_, 0, ref bi, 40);
        if (hr != 0)
        {
            throw new AviException("AVIStreamSetFormat", hr);
        }
    }
Example #3
0
        /// <summary>
        /// オーディオ圧縮の設定ダイアログを表示し、オーディオ圧縮の設定を取得します
        /// </summary>
        /// <returns></returns>
        unsafe public static AVICOMPRESSOPTIONS RequireAudioCompressOption()
        {
            string temp_file = Path.GetTempFileName();

            byte[] buf = new byte[] {
                82, 73, 70, 70, 94, 0, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32, 16, 0, 0, 0, 1,
                0, 1, 0, 64, 31, 0, 0, 64, 31, 0, 0, 1, 0, 8, 0, 100, 97, 116, 97, 58, 0, 0, 0,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
            };
            using (FileStream fs = new FileStream(temp_file, FileMode.Create)) {
                fs.Write(buf, 0, buf.Length);
            }

            AVIFileInit();
            //MessageBox.Show( "AVIFileInit ok" );
            IntPtr audio;
            int    hr = AVIStreamOpenFromFileW(out audio, temp_file, _STREAM_TYPE_AUDIO, 0, OF_READ, 0);
            //MessageBox.Show( "AVIStreamOpenFromFileW ok" );

            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();

            opts.fccType           = _STREAM_TYPE_AUDIO; //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;
            AVICOMPRESSOPTIONS * p  = &opts;
            AVICOMPRESSOPTIONS **pp = &p;
            IntPtr  x      = audio;
            IntPtr *ptr_ps = &x;

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

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

            AVIFileExit();
            //MessageBox.Show( "AVIFileExit ok" );
            File.Delete(temp_file);
            return(copied);
        }
Example #4
0
        /// <summary>
        /// 设置参数
        /// </summary>
        unsafe private void SetOptions()
        {
            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();

            opts.fccType           = _fccType;
            opts.fccHandler        = 0;
            opts.dwKeyFrameEvery   = 0;
            opts.dwQuality         = 0;
            opts.dwFlags           = 0;
            opts.dwBytesPerSecond  = 0;
            opts.lpFormat          = new IntPtr(0);
            opts.cbFormat          = 0;
            opts.lpParms           = new IntPtr(0);
            opts.cbParms           = 0;
            opts.dwInterleaveEvery = 0;

            AVICOMPRESSOPTIONS * p  = &opts;
            AVICOMPRESSOPTIONS **pp = &p;

            IntPtr  x      = _ps;
            IntPtr *ptr_ps = &x;

            AVISaveOptions(0, 0, 1, ptr_ps, pp);

            int hr = AVIMakeCompressedStream(out _psCompressed, _ps, ref
                                             opts, 0);

            if (hr != 0)
            {
                throw new AviException("AVIMakeCompressedStream");
            }

            BITMAPINFOHEADER bi = new BITMAPINFOHEADER();

            bi.biSize          = 40;
            bi.biWidth         = (Int32)_width;
            bi.biHeight        = (Int32)_height;
            bi.biPlanes        = 1;
            bi.biBitCount      = 24;
            bi.biCompression   = 0;
            bi.biSizeImage     = _stride * _height;
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed       = 0;
            bi.biClrImportant  = 0;

            hr = AVIStreamSetFormat(_psCompressed, 0, ref bi, 40);
            if (hr != 0)
            {
                throw new AviException("AVIStreamSetFormat", hr);
            }
        }
Example #5
0
File: AVIRec.cs Project: uvbs/Razor
        unsafe private bool SetOptions()
        {
            int hr;
            AVICOMPRESSOPTIONS  opts  = new AVICOMPRESSOPTIONS();
            AVICOMPRESSOPTIONS *pOpts = &opts;

            /*
             * opts.fccType           = mmioFOURCC('v','i','d','s');
             * opts.fccHandler        = 0;//cvid? iv50?
             * opts.dwQuality         = 0;  // 0 .. 10000
             * opts.dwFlags           = 0;  // AVICOMRPESSF_KEYFRAMES = 4
             */

            hr = AVISaveOptions(Engine.MainWindow.Handle, 3, 1, ref m_pStream, &pOpts);
            if (hr != 1)
            {
                return(false);
            }

            // TODO: AVISaveOptionsFree(...)

            hr = AVIMakeCompressedStream(out m_pCompStream, m_pStream, ref opts, 0);
            if (hr != 0)
            {
                return(false);
            }

            BITMAPINFOHEADER bi = new BITMAPINFOHEADER();

            bi.biSize        = 40;
            bi.biWidth       = m_Width;
            bi.biHeight      = m_Height;
            bi.biPlanes      = 1;
            bi.biBitCount    = 24;
            bi.biCompression = 0;               // 0 = BI_RGB
            bi.biSizeImage   = (uint)(m_Width * m_Height * (bi.biBitCount / 8));

            hr = AVIStreamSetFormat(m_pCompStream, 0, ref bi, 40);
            return(hr == 0);
        }
Example #6
0
        unsafe private AVICOMPRESSOPTIONS GetOption()
        {
            IntPtr             x      = _ps;
            IntPtr *           ptr_ps = &x;
            AVICOMPRESSOPTIONS _compressedOption;

            if (_compressedOptionData != null)
            {
                try
                {
                    _compressedOption = CommonMethods.RawDeserialize <AVICOMPRESSOPTIONS>(_compressedOptionData);
                    return(_compressedOption);
                }
                catch { }
            }

            _compressedOption                   = new AVICOMPRESSOPTIONS();
            _compressedOption.fccType           = _fccType;
            _compressedOption.fccHandler        = 0;
            _compressedOption.dwKeyFrameEvery   = 0;
            _compressedOption.dwQuality         = 0;
            _compressedOption.dwFlags           = 0;
            _compressedOption.dwBytesPerSecond  = 0;
            _compressedOption.lpFormat          = new IntPtr(0);
            _compressedOption.cbFormat          = 0;
            _compressedOption.lpParms           = new IntPtr(0);
            _compressedOption.cbParms           = 0;
            _compressedOption.dwInterleaveEvery = 0;

            AVICOMPRESSOPTIONS * p  = &_compressedOption;
            AVICOMPRESSOPTIONS **pp = &p;

            AVISaveOptions(0, 0, 1, ptr_ps, pp);

            _compressedOptionData = CommonMethods.RawSerialize(_compressedOption);

            return(_compressedOption);
        }
Example #7
0
        /**
         * Sets the recording options of the AVI stream
         * @return void
         * @private
         */
        unsafe private void SetOptions()
        {
            string[] codecs = GetSortedCodecs();
            if (codecs.Length < 1)
            {
                throw new Exception("No codecs found.");
            }

            string usefourcc;

            //Check for more efficient lossy codecs
            //Just a note: There is probably a better way to handle this
            if (Array.IndexOf(codecs, "XVID") > -1)
            {
                usefourcc = codecs[Array.IndexOf(codecs, "XVID")];             //Great codec!
            }
            else if (Array.IndexOf(codecs, "DIVX") > -1)
            {
                usefourcc = codecs[Array.IndexOf(codecs, "XVID")];             //Another good one!
            }
            else if (Array.IndexOf(codecs, "UYVY") > -1)
            {
                usefourcc = codecs[Array.IndexOf(codecs, "UYVY")];             //used for hd
            }
            else if (Array.IndexOf(codecs, "mrle") > -1)
            {
                usefourcc = codecs[Array.IndexOf(codecs, "mrle")];             //poor quality
            }
            else if (Array.IndexOf(codecs, "msvc") > -1)
            {
                usefourcc = codecs[Array.IndexOf(codecs, "msvc")];             //Shipped with windows (let's default to this)
            }
            else
            {
                usefourcc = codecs[0];              //Could find any in the list, let's just default to the first one.
            }

            //UnityEngine.Debug.Log("Chose codec: "+usefourcc);

            //Here let's create the FourCC
            FourCC.FourCC fcc = new FourCC.FourCC(usefourcc);

            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();

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


            AVICOMPRESSOPTIONS * p  = &opts;
            AVICOMPRESSOPTIONS **pp = &p;

            IntPtr  x      = ps_;
            IntPtr *ptr_ps = &x;


            int hr = AVIMakeCompressedStream(out psCompressed_, ps_, ref opts, 0);

            if (hr != 0)
            {
                throw new AviException("AVIMakeCompressedStream");
            }

            BITMAPINFOHEADER bi = new BITMAPINFOHEADER();

            bi.biSize          = 40;
            bi.biWidth         = (Int32)width_;
            bi.biHeight        = (Int32)height_;
            bi.biPlanes        = 1;
            bi.biBitCount      = 24;
            bi.biCompression   = 0;             // 0 = BI_RGB
            bi.biSizeImage     = stride_ * height_;
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed       = 0;
            bi.biClrImportant  = 0;

            hr = AVIStreamSetFormat(psCompressed_, 0, ref bi, 40);
            if (hr != 0)
            {
                throw new AviException("AVIStreamSetFormat", hr);
            }
        }
Example #8
0
        unsafe private void SetOptions()
        {
            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS
            {
                fccType           = fccType_,
                fccHandler        = 0, // 541215044;//fccHandler_;
                dwKeyFrameEvery   = 0,
                dwQuality         = 0, // 0 .. 10000
                dwFlags           = 8, // AVICOMRPESSF_KEYFRAMES = 4
                dwBytesPerSecond  = 0,
                lpFormat          = new IntPtr(0),
                cbFormat          = 0,
                lpParms           = new IntPtr(0),
                cbParms           = 0,
                dwInterleaveEvery = 0
            };

            AVICOMPRESSOPTIONS * p  = &opts;
            AVICOMPRESSOPTIONS **pp = &p;

            IntPtr  x      = ps_;
            IntPtr *ptr_ps = &x;

            //          AVISaveOptions(0,1,1,ptr_ps,pp);

            //            ps_ = (System.IntPtr) 3798676;

            // TODO: AVISaveOptionsFree(...)

            int hr = AVIMakeCompressedStream(out psCompressed_, ps_, ref opts, 0);

            if (hr != 0)
            {
                //throw new AviException("AVIMakeCompressedStream");
                AVISaveOptions(0, 1, 1, ptr_ps, pp);
                hr = AVIMakeCompressedStream(out psCompressed_, ps_, ref opts, 0);
                if (hr != 0)
                {
                    throw new Exception("AVIMakeCompressedStream");
                }
            }

            BITMAPINFOHEADER bi = new BITMAPINFOHEADER
            {
                biSize          = 40,
                biWidth         = (Int32)width_,
                biHeight        = (Int32)height_,
                biPlanes        = 1,
                biBitCount      = 24,
                biCompression   = 0, // 0 = BI_RGB
                biSizeImage     = stride_ * height_,
                biXPelsPerMeter = 0,
                biYPelsPerMeter = 0,
                biClrUsed       = 0,
                biClrImportant  = 0
            };

            hr = AVIStreamSetFormat(psCompressed_, 0, ref bi, 40);
            if (hr != 0)
            {
                throw new Exception("AVIStreamSetFormat");
            }
        }
Example #9
0
        unsafe private bool SetOptions(IntPtr hwnd)
        {
            // VIDEO
            AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();

            opts.fccType           = 0;
            opts.fccHandler        = 0;
            opts.dwKeyFrameEvery   = 0;
            opts.dwQuality         = 0;
            opts.dwFlags           = 0;
            opts.dwBytesPerSecond  = 0;
            opts.lpFormat          = new IntPtr(0);
            opts.cbFormat          = 0;
            opts.lpParms           = new IntPtr(0);
            opts.cbParms           = 0;
            opts.dwInterleaveEvery = 0;

            AVICOMPRESSOPTIONS * p = &opts;
            AVICOMPRESSOPTIONS **pp;

            pp = &p;
            IntPtr  x = m_video;
            IntPtr *ptr_ps;

            ptr_ps = &x;
            if (AVISaveOptions(hwnd, 0, 1, ptr_ps, pp) == 0)
            {
                return(false);
            }
            int hr = AVIMakeCompressedStream(out m_video_compressed, m_video, ref opts, 0);

            if (hr != 0)
            {
                throw new AviException("AVIMakeCompressedStream; Video");
            }
            m_strh_fcc = opts.fccHandler;
#if DEBUG
            Console.WriteLine("AviWriterVfw+SetOptions");
            Console.WriteLine("    opts.fccHandler=" + opts.fccHandler);
#endif

            // TODO: AVISaveOptionsFree(...)
            BITMAPINFO bi = new BITMAPINFO();
            bi.bmiHeader.biSize          = 40;
            bi.bmiHeader.biWidth         = (Int32)m_width;
            bi.bmiHeader.biHeight        = (Int32)m_height;
            bi.bmiHeader.biPlanes        = 1;
            bi.bmiHeader.biBitCount      = 24;
            bi.bmiHeader.biCompression   = 0;
            bi.bmiHeader.biSizeImage     = m_stride * m_height;
            bi.bmiHeader.biXPelsPerMeter = 0;
            bi.bmiHeader.biYPelsPerMeter = 0;
            bi.bmiHeader.biClrUsed       = 0;
            bi.bmiHeader.biClrImportant  = 0;

            hr = AVIStreamSetFormat(m_video_compressed, 0, ref bi, sizeof(BITMAPINFO));
            if (hr != 0)
            {
                throw new AviException("AVIStreamSetFormat", hr);
            }
#if DEBUG
            Console.WriteLine("    bi.bmiHeader.biCompression=" + bi.bmiHeader.biCompression);
#endif
            return(true);
        }
Example #10
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);
        }