Home » ASP.NET » Aforge video capture, grab pictures, video recordi...

Aforge video capture, grab pictures, video recording, WPF, use Image controls to display video

1. - >
Add Reference
AForge

AForge.Video.DirectShow

AForge.Video

AForge.Video.FFMPEG

AForge.Video.Controls



2. uses AForge.Video.FFMPEG to record video, so you need the following settings

1 configuration manager) - > > changed: x86
2) App.config is modified as:

XML? Version= "1" encoding= "UTF-8" >









3) copy all files from AForge.NET Framework-2.2.5- (LIBS, only) Externalsffmpegbin directory to

ProjectsWpfApplication3WpfApplication3binx86Debug (your project Debug directory)



3. video capture

1) WPF adds the VideoSourcePlayer control because it is a WinForms control and requires the use of WindowsFormsHost








2) get the video device, turn on the video

private, FilterInfoCollection, videoDevices,

private, VideoCaptureDevice, div = null;

// set the initial video equipment > videoDevices = new, FilterInfoCollection (FilterCategory.VideoInputDevice);

if (videoDevices.Count > 0)

{/ /
default device
div = new, VideoCaptureDevice (videoDevices[0].MonikerString);

sourcePlayer.VideoSource = div;

}

sourcePlayer.Start ();





4. grab picture

System.Windows.Controls.Image, image = new, System.Windows.Controls.Image ();

image.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap (

sourcePlayer.GetCurrentVideoFrame (),.GetHbitmap (),

IntPtr.Zero,

Int32Rect.Empty,

BitmapSizeOptions.FromEmptyOptions ());





5. recording video

1) using NewFrame events in two ways,

first is the NewFrame event of the VideoSourcePlayer control: private, void, sourcePlayer_NewFrame (object, sender, ref, image, Bitmap)

generates the event code using the control:

note: private, void, sourcePlayer_NewFrame (object, sender, Bitmap, image), the parameter is missing the ref reference, and you need to manually modify

use code to control binding events:

sourcePlayer.NewFrame = new AForge.Controls.VideoSourcePlayer.NewFrameHandler (sourcePlayer_NewFrame);

finished recording video Unbound:

sourcePlayer.NewFrame = new AForge.Controls.VideoSourcePlayer.NewFrameHandler (sourcePlayer_NewFrame);



two is the NewFrame event of the VideoCaptureDevice object: void videoSource_NewFrame (object, sender, AForge.Video.NewFrameEventArgs, eventArgs),

use code to control binding events:

div.NewFrame = new NewFrameEventHandler (videoSource_NewFrame);

finished recording video Unbound:

div.NewFrame = new NewFrameEventHandler (videoSource_NewFrame);



2) in the NewFrame event, use the VideoFileWriter object to write the video file >



6.WPF under the WinForms control label, WindowsFormsHost will block the WPF control, display problems

instead of the VideoSourcePlayer control, you can use the WPF standard control Image to constantly refresh the Image.Source in the NewFrame event because it is the property value of cross thread control of the Image control,

needs to be refreshed using the delegate method Image.Source

Latest