Use Capture to load a video.
Use the Getcaptureproperty function to get the various properties of this video.
Then use Application.idle to continuously display the frame in the video (showing a frame, the program enters the idle, continues to load the next frame)
Because there are too many frames in the video, the. NET garbage collection mechanism will not catch up, use Gc.collect (), to force garbage collection, you can reduce the memory consumption of the program from 700MB to about 100MB
Public Partial classform1:form {Capture cap;intfps Public Form1() {InitializeComponent (); OpenFileDialog OpenFileDialog =NewOpenFileDialog (); Openfiledialog.filter ="MP4 file |*.mp4| AVI file |*.avi| RMVB file |*.rmvb| WMV file |*.wmv| MKV file |*.mkv| All files |*.* ";if(Openfiledialog.showdialog () = = DialogResult.OK) {Application.idle + = Application_idle; Cap =NewCapture (Openfiledialog.filename); fps = (int) cap. Getcaptureproperty (Capprop.fps); } }Private void Application_idle(Objectsender, EventArgs e) {Mat a = cap. Queryframe ();if(A! =NULL) {System.Threading.Thread.Sleep (int)(1000.0/FPS-5)); Imagebox1.image = A; Gc. Collect (); } } }
:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Play a specified video using EMGUCV