示例#1
0
        private void makeVideo(string bmpDir, string distFile)
        {
            double Rate = 10;

            Avi.AVICOMPRESSOPTIONS aviformat = new Avi.AVICOMPRESSOPTIONS();
            aviformat.cbFormat   = 0;
            aviformat.cbParms    = 4;
            aviformat.dwFlags    = 8;
            aviformat.dwQuality  = 7500;
            aviformat.fccHandler = 1668707181;

            AviManager  aviManager = new AviManager(distFile, false);
            Bitmap      bitmap0    = (Bitmap)Image.FromFile(@bmpDir + "0.bmp");
            VideoStream aviStream  = aviManager.AddVideoStream(aviformat, Rate, bitmap0);

            string[] bmpFiles = Directory.GetFiles(bmpDir, "*.bmp");
            for (Int32 i = 1; i < bmpFiles.Length; i++)
            {
                Bitmap bitmap = (Bitmap)Bitmap.FromFile(bmpFiles[i]);
                aviStream.AddFrame(bitmap);
                bitmap.Dispose();
                System.Threading.Thread.Sleep(5);
            }
            aviManager.Close();
        }
示例#2
0
        public void CaptureVideo()
        {
            b = new Bitmap(ScreenWidth, ScreenHeight);
            g = Graphics.FromImage(b);
            g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);


            //auto set options for video recording
            //(description for each option availible at http://msdn.microsoft.com/en-us/library/windows/desktop/dd756832(v=vs.85).aspx)
            Avi.AVICOMPRESSOPTIONS aviOptions = new Avi.AVICOMPRESSOPTIONS();
            aviOptions.fccType = (uint)Avi.streamtypeVIDEO;
            //codec to use MSVC = Microsoft Video 1
            aviOptions.fccHandler = (uint)Avi.mmioStringToFOURCC("MSVC", 0);
            //quality option go from 0-10000
            aviOptions.dwQuality = 5000;

            //change aviOptions to "true" to enable the popup window asking for codec options eg. aviStream = aviManager.AddVideoStream(true, 4, b);
            aviStream = aviManager.AddVideoStream(aviOptions, 4, b);

            Bitmap tempBmp;

            while (!pause)
            {
                tempBmp = new Bitmap(ScreenWidth, ScreenHeight);
                g       = Graphics.FromImage(tempBmp);
                g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
                g.FillEllipse(fillBrush, currentPoint.X, currentPoint.Y, 10, 10);
                g.FillRectangle(new SolidBrush(Color.Black), ScreenWidth - 100, ScreenHeight - 30, 100, 30);
                g.DrawString(elapsedTime, new Font("Arial", 12), new SolidBrush(Color.White), new PointF(ScreenWidth - 95, ScreenHeight - 25));

                if (tempBmp != null)
                {
                    try
                    {
                        aviStream.AddFrame(tempBmp);
                    }
                    catch
                    {
                        Bitmap bmp2 = tempBmp;
                        tempBmp.Dispose();
                        tempBmp = new Bitmap((Image)bmp2);
                        aviStream.AddFrame(tempBmp);
                    }
                }
                tempBmp.Dispose();
                Thread.Sleep(50);
            }
            aviManager.Close();
        }
示例#3
0
        private Avi.AVICOMPRESSOPTIONS createCompressedOptions()
        {
            Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
            opts.fccType           = (UInt32)Avi.mmioStringToFOURCC("vids", 0);
            opts.fccHandler        = (UInt32)Avi.mmioStringToFOURCC("CVID", 0);
            opts.dwKeyFrameEvery   = 0;
            opts.dwQuality         = 0;                         // 0 .. 10000
            opts.dwFlags           = Avi.AVICOMPRESSF_DATARATE; // 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;

            return(opts);
        }
示例#4
0
		/// <summary>Create a compressed stream from an uncompressed stream</summary>
		private void CreateCompressedStream(Avi.AVICOMPRESSOPTIONS options) {
			int result = Avi.AVIMakeCompressedStream(out compressedStream, aviStream, ref options, 0);
			if (result != 0) {
				throw new Exception("Exception in AVIMakeCompressedStream: " + result);
			}

			compressOptions = options;

			SetFormat(compressedStream);
		}
示例#5
0
		/// <summary>Create a compressed stream from an uncompressed stream</summary>
		private void CreateCompressedStream() {
			//display the compression options dialog...
			Avi.AVICOMPRESSOPTIONS_CLASS options = new Avi.AVICOMPRESSOPTIONS_CLASS {
				fccType = (uint)Avi.streamtypeVIDEO,
				lpParms = IntPtr.Zero,
				lpFormat = IntPtr.Zero
			};

			Avi.AVISaveOptions(IntPtr.Zero, Avi.ICMF_CHOOSE_KEYFRAME | Avi.ICMF_CHOOSE_DATARATE, 1, ref aviStream, ref options);
			Avi.AVISaveOptionsFree(1, ref options);

			//..or set static options
			/*Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
			opts.fccType         = (UInt32)Avi.mmioStringToFOURCC("vids", 0);
			opts.fccHandler      = (UInt32)Avi.mmioStringToFOURCC("CVID", 0);
			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;*/

			//get the compressed stream
			compressOptions = options.ToStruct();
			int result = Avi.AVIMakeCompressedStream(out compressedStream, aviStream, ref compressOptions, 0);
			if (result != 0) {
				throw new Exception("Exception in AVIMakeCompressedStream: " + result);
			}

			SetFormat(compressedStream);
		}
示例#6
0
		/// <summary>Copy all properties from one VideoStream to another one</summary>
		/// <remarks>Used by EditableVideoStream</remarks>
		/// <param name="frameSize"></param><param name="frameRate"></param>
		/// <param name="width"></param><param name="height"></param>
		/// <param name="countBitsPerPixel"></param>
		/// <param name="countFrames"></param><param name="compressOptions"></param>
		internal VideoStream(int frameSize, double frameRate, int width, int height, Int16 countBitsPerPixel, int countFrames, Avi.AVICOMPRESSOPTIONS compressOptions, bool writeCompressed) {
			FrameSize = frameSize;
			FrameRate = frameRate;
			Width = width;
			Height = height;
			CountBitsPerPixel = countBitsPerPixel;
			CountFrames = countFrames;
			this.compressOptions = compressOptions;
			this.writeCompressed = writeCompressed;
			FirstFrame = 0;
		}