Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Compressor[] comp = EnumCompressors();
            foreach (Compressor c in comp)
            {
                Console.WriteLine(c.name);
            }

            Console.WriteLine("---");

            // create BitmapWriter component and configure it
            IBitmapWriter writer = (IBitmapWriter) new CVideoRecorder();

            writer.Init(100, 100, 5);

            // create DirectShow graph builder
            ICaptureGraphBuilder2 builder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2Cls();

            // create AVIMux and file writer component
            IBaseFilter     pMux;
            IFileSinkFilter unused;

            builder.SetOutputFileName(ref MEDIASUBTYPE_Avi, "test.avi", out pMux, out unused);

            IGraphBuilder graph;

            builder.GetFiltergraph(out graph);

            // add BitmapWriter as the source component
            graph.AddFilter((IBaseFilter)writer, "source");
            // if the compressor is specified, add it
            IBaseFilter compressor = null;

            if (args.Length != 0)
            {
                compressor = comp[int.Parse(args[0])].compressor;
                graph.AddFilter(compressor, "compressor");
            }

            // connect components
            builder.RenderStream(IntPtr.Zero, IntPtr.Zero, writer, compressor, pMux);

            // run the graph and send images
            IMediaControl control = (IMediaControl)graph;

            control.Run();
            for (int i = 0; i < 10; i++)
            {
                Bitmap bmp  = new Bitmap(@"..\..\test" + (i % 2) + ".bmp");
                IntPtr hBmp = bmp.GetHbitmap();
                writer.WriteBitmap((uint)hBmp.ToInt32());
                DeleteObject(hBmp);
                bmp.Dispose();
            }

            // stop the graph and flash any pending data throught the pipeline
            control.Stop();

            Console.WriteLine("done");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Captures the current frame.
        /// </summary>
        private void capture()
        {
            if (currentState != State.Recording)
            {
                return;                         // don't do this unless we are actually recording.
            }
            Debug.WriteLine("capturing video frame");

            using (Bitmap bmp = drawer.createBitmap()) {
                IntPtr hBmp = bmp.GetHbitmap();
                writer.WriteBitmap((uint)hBmp.ToInt32());
                DeleteObject(hBmp);
            }
        }