Пример #1
0
        public void AddWave(string wave_filename)
        {
            byte[]       wave_data = File.ReadAllBytes(wave_filename);
            MemoryStream header    = new MemoryStream();

            header.Write(wave_data, 0, 36);
            header.Seek(0, SeekOrigin.Begin);
            BinaryReader reader = new BinaryReader(header);

            reader.ReadBytes(20);

            IntPtr wave_ptr      = Marshal.AllocHGlobal(wave_data.Length);
            IntPtr wave_data_ptr = new IntPtr(wave_ptr.ToInt32() + 44);

            try
            {
                Marshal.Copy(wave_data, 0, wave_ptr, wave_data.Length);

                VfwApi.PCMWAVEFORMAT pwformat = new VfwApi.PCMWAVEFORMAT();
                pwformat.wFormatTag      = reader.ReadInt16();
                pwformat.nChannels       = reader.ReadInt16();
                pwformat.nSamplesPerSec  = reader.ReadInt32();
                pwformat.nAvgBytesPerSec = reader.ReadInt32();
                pwformat.nBlockAlign     = reader.ReadInt16();
                pwformat.wBitsPerSample  = reader.ReadInt16();

                int sample_size = pwformat.nChannels * pwformat.wBitsPerSample / 8;

                CreateAudioStream(pwformat.nSamplesPerSec, (wave_data.Length - 44) / sample_size, sample_size);

                int hr = VfwApi.AVIStreamSetFormat(pavi_audio_, 0, ref pwformat, Marshal.SizeOf(pwformat));
                if (hr != 0)
                {
                    throw new VfwException("AVIStreamSetFormat", hr);
                }

                hr = VfwApi.AVIStreamWrite(pavi_audio_, 0, wave_data.Length - 44, wave_data_ptr,
                                           wave_data.Length - 44, 16, IntPtr.Zero, IntPtr.Zero);
                if (hr != 0)
                {
                    throw new VfwException("AVIStreamWrite", hr);
                }

                VfwApi.AVIStreamRelease(pavi_audio_);
                pavi_audio_ = IntPtr.Zero;
            }
            finally
            {
                Marshal.FreeHGlobal(wave_ptr);
            }
        }
Пример #2
0
        private void SetVideoFormat(int width, int height, int stride, int bit_count)
        {
            VfwApi.BITMAPINFOHEADER binfo = new VfwApi.BITMAPINFOHEADER();
            binfo.biSize          = Marshal.SizeOf(binfo);
            binfo.biWidth         = width;
            binfo.biHeight        = height;
            binfo.biPlanes        = 1;
            binfo.biBitCount      = (short)bit_count;
            binfo.biCompression   = 0;
            binfo.biSizeImage     = height * stride;
            binfo.biXPelsPerMeter = 0;
            binfo.biYPelsPerMeter = 0;
            binfo.biClrUsed       = 0;
            binfo.biClrImportant  = 0;

            int hr = VfwApi.AVIStreamSetFormat(pavi_, 0, ref binfo, binfo.biSize);

            if (hr != 0)
            {
                throw new VfwException("AVIStreamSetFormat", hr);
            }
        }