1

我需要找到一种方法,如何在 C#(Windows 应用程序)中从 2 个或更多网络摄像头制作一个视频文件。我尝试使用谷歌查找一些样本,但没有成功。我找到了一种从网络摄像头录制视频的方法(使用directshowNet,directx,我可以用两个网络摄像头保存两个avi ...)

有关 directShowNet 的更多信息:

http://directshownet.sourceforge.net/

捕获视频的示例:

http://www.codeproject.com/KB/directx/directshownet.aspx

举一个简单的例子,我有 2 个网络摄像头。我需要在录制过程中获取帧,将一帧粘贴到另一帧附近(制作一张图像,从两者中创建一帧),然后将这些新帧插入到新的 avi 中。任何想法?是否可以及时获取帧,并从捕获的 2 个 avi 中创建一个新的 avi?

4

2 回答 2

1

这个问题有点老了(!)但以防万一:我已经成功使用了AForge.NET库。在其 2.1.4 版本中,它有一个示例,可以显示来自两个摄像头的视频。
您所要做的就是不要使用默认的视频播放器控件,而是使用VideoCaptureDevice并在 NewFrame 事件中创建您想要的位图。AForge.NET 甚至有一个AVIWriter可用于创建输出视频。

于 2010-09-30T08:50:38.910 回答
0

这里是合并 2 个图像的代码

#region TakeSnap Class

    IntPtr memDc;
    [StructLayout(LayoutKind.Sequential)]
        public struct Sizes
    {
        public Int32 cx;
        public Int32 cy;

        public Sizes(Int32 x, Int32 y)
        {
            cx = x;
            cy = y;
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct BLENDFUNCTION
    {
        public byte BlendOp;
        public byte BlendFlags;
        public byte SourceConstantAlpha;
        public byte AlphaFormat;
    }

    [StructLayout(LayoutKind.Sequential)]
        public struct Points
    {
        public Int32 x;
        public Int32 y;

        public Points(Int32 x, Int32 y)
        {
            this.x = x;
            this.y = y;
        }
    }

    [DllImport("gdi32.dll",EntryPoint="DeleteDC")]
    public static extern IntPtr DeleteDC(IntPtr hDc);

    [DllImport("gdi32.dll",EntryPoint="DeleteObject")]
    public static extern IntPtr DeleteObject(IntPtr hDc);

    [DllImport("gdi32.dll",EntryPoint="BitBlt")]
    public static extern bool BitBlt(IntPtr hdcDest,int xDest,
        int yDest,int wDest,int hDest,IntPtr hdcSource,
        int xSrc,int ySrc,int RasterOp);

    [DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
    public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
        int nWidth, int nHeight);

    [DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
    public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

    [DllImport ("gdi32.dll",EntryPoint="SelectObject")]
    public static extern IntPtr SelectObject(IntPtr hdc,IntPtr bmp);

    [DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
    public static extern IntPtr GetDesktopWindow();

    [DllImport("user32.dll",EntryPoint="GetDC")]
    public static extern IntPtr GetDC(IntPtr ptr);

    [DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
    public static extern int GetSystemMetrics(int abc);

    [DllImport("user32.dll",EntryPoint="GetWindowDC")]
    public static extern IntPtr GetWindowDC(Int32 ptr);

    [DllImport("user32.dll",EntryPoint="ReleaseDC")]
    public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDc);

    protected static IntPtr m_HBitmap;
    public const int SM_CXSCREEN=0;
    public const int SM_CYSCREEN=1;
    public const int SRCCOPY = 13369376;

    #endregion



  private IntPtr get_pointer(string path)
    {

        Bitmap bitmap=new Bitmap(path);
        IntPtr oldBits = IntPtr.Zero;
        IntPtr screenDC = GetDC(IntPtr.Zero);
        IntPtr hBitmap = IntPtr.Zero;
        memDc = CreateCompatibleDC(screenDC);

        try
        {
            Point topLoc = new Point(Left, Top);
            Sizes bitMapSize = new Sizes(bitmap.Width, bitmap.Height);
            BLENDFUNCTION blendFunc = new BLENDFUNCTION();
            Points srcLoc = new Points(0, 0);

            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            IntPtr pt= SelectObject(memDc, hBitmap);
            ReleaseDC(IntPtr.Zero, screenDC);               
            return memDc;
        }
        catch(Exception ex)
        {
            return this.Handle;
        }

    }       
    public  Bitmap GetDesktopImage()
    {
        try
        {               

            Sizes size; 
            IntPtr hBitmap;         
            IntPtr  hDC = get_pointer(@"C:\Documents and Settings\admin\Desktop\11_13_40_453.jpg");             
            IntPtr hMemDC = CreateCompatibleDC(hDC);
            IntPtr  hDC1 = get_pointer(@"C:\Documents and Settings\admin\Desktop\11_13_42_906.jpg");        

            size.cx = this.Width-2;
            size.cy = this.Height-22;
            hBitmap = CreateCompatibleBitmap(hDC, size.cx*2, size.cy);          
            if (hBitmap!=IntPtr.Zero)
            {
                IntPtr hOld = (IntPtr)SelectObject(hMemDC, hBitmap);                    
                BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC,0, 0,SRCCOPY); 
                BitBlt(hMemDC, size.cx, 0,size.cx,size.cy, hDC1,0, 0,SRCCOPY);
                SelectObject(hMemDC, hOld);                         
                DeleteDC(hMemDC);                   
                DeleteDC(memDc);                    
                ReleaseDC(this.Handle, hDC);
                ReleaseDC(this.Handle, hDC1);               
                Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);                 
                DeleteObject(hBitmap);              
                GC.Collect();               
                return bmp;
            }           
            return null;

        }
        catch(Exception ex)
        {           
            return null;
        }
    }


    private void Createimage()
    {
        try
        {
            Bitmap bm= GetDesktopImage();
            bm.Save(Application.StartupPath+"\\temp\\"+DateTime.Now.ToString("hh-mm-ss ff")+".Jpeg",System.Drawing.Imaging.ImageFormat.Jpeg);
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }
于 2009-08-07T11:57:32.150 回答