/// <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); } }
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); } }
/// <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); }
/// <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); } }
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); }
unsafe public static extern int AVISaveOptions(int hwnd, UInt32 uiFlags, int nStreams, IntPtr *ppavi, AVICOMPRESSOPTIONS **plpOptions);
unsafe private static extern int AVISaveOptions( int hwnd, UInt32 flags, int nStreams, IntPtr *ptr_ptr_avi, AVICOMPRESSOPTIONS **ao);
/** * 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); } }
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"); } }
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); }
public static unsafe extern int AVISaveOptions( IntPtr hwnd, UInt32 flags, int nStreams, IntPtr *ptr_ptr_avi, AVICOMPRESSOPTIONS **ao);
unsafe private static extern int AVISaveOptions(IntPtr hwnd, uint flags, int nStreams, ref IntPtr pStream, AVICOMPRESSOPTIONS **aco);