public void Start() { Debug.WriteLine("Starting..."); if (aviStream != null || aviManager != null) { Debug.WriteLine("AviManager is not null!"); } Sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat); string path = Path.Combine(KissHelper.GetPath(), "kiss-" + time + ".avi"); aviManager = new AviManager(path, false); BitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(ColorBitmap)); MemoryStream s = new MemoryStream(); encoder.Save(s); Bitmap b = (Bitmap)Image.FromStream(s); Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS(); opts.fccType = 0; // (UInt32)Avi.mmioStringToFOURCC("mrle", 0); opts.fccHandler = 1684633187;// (UInt32)Avi.mmioStringToFOURCC("MRLE", 0); opts.dwKeyFrameEvery = 0; opts.dwQuality = 10000; // 0 .. 10000 opts.dwFlags = 10; // AVICOMRPESSF_KEYFRAMES = 4 opts.dwBytesPerSecond = 204800; opts.lpFormat = new IntPtr(0); opts.cbFormat = 0; opts.lpParms = new IntPtr(0); opts.cbParms = 4; opts.dwInterleaveEvery = 0; aviStream = aviManager.AddVideoStream(opts, 1000.0 / Properties.Settings.Default.TickMsec, b); if (OnStart != null) OnStart(null); Debug.WriteLine("Started."); }
/// <summary>Create a new AVI Player</summary> /// <param name="videoStream">Video stream to play</param> /// <param name="picDisplay">PictureBox to display the video</param> /// <param name="ctlFrameIndexFeedback">Optional Label to show the current frame index</param> public AviPlayer(VideoStream videoStream, PictureBox picDisplay, Control ctlFrameIndexFeedback) { this.videoStream = videoStream; this.picDisplay = picDisplay; this.ctlFrameIndexFeedback = ctlFrameIndexFeedback; this.isRunning = false; }
public ScreenCapture(int fps, Screen screen) { string x = System.DateTime.Now.ToString(); x = x.Replace(@"/", "."); x = x.Replace(@":", "."); strPath = @"/Videos/"; intTop = screen.Bounds.X; intleft = screen.Bounds.Y; intWidth = screen.Bounds.Width; intHeight = screen.Bounds.Height; size = screen.Bounds.Size; capture(); aviMan = new AviManager(x + ".avi", false); videoStream = aviMan.AddVideoStream(true, 30, printscreen); printscreen.Dispose(); Console.WriteLine(strPath); System.IO.Directory.CreateDirectory(strPath); System.Timers.Timer aTimer; aTimer = new System.Timers.Timer(); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Interval = 1000 / fps; aTimer.Enabled = true; }
public VideoFrames(string fileLocation) { if (fileLocation == null) { _mode = Mode.None; return; } string lower = fileLocation.ToLower(); fileloc = fileLocation; if (lower.EndsWith(".avi")) { _aviManager = new AviManager(fileLocation, true); _aviStream = _aviManager.GetVideoStream(); _aviStream.GetFrameOpen(); _mode = Mode.Video; } else if (lower.EndsWith(".png")) { _singleFrame = new System.Drawing.Bitmap(fileLocation); _mode = Mode.SingleFrame; } else { _mode = Mode.None; } }
public VideoStreamRoadPartControl(VideoStream videoStream) { InitializeComponent(); Width = videoStream.CountFrames; VideoStream = videoStream; MoveEnable = true; LeftCoordinate = 0; RightCoordinate = Width; }
/// <summary>Create an editable stream from an uneditable stream</summary> /// <param name="stream">uneditable stream</param> public EditableVideoStream(VideoStream stream) : base(stream.FrameSize, stream.FrameRate, stream.Width, stream.Height, stream.CountBitsPerPixel, stream.CountFrames, stream.CompressOptions, stream.WriteCompressed) { Avi.NativeMethods.AVIFileInit(); int result = Avi.NativeMethods.CreateEditableStream(ref editableStream, stream.StreamPointer); if (result != 0) { throw new Exception("Exception in CreateEditableStream: " + result.ToString()); } SetInfo(stream.StreamInfo); }
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(); }
/// <summary>Get the first video stream - usually there is only one video stream</summary> /// <returns>VideoStream object for the stream</returns> public VideoStream GetVideoStream(){ IntPtr aviStream; int result = Avi.AVIFileGetStream( aviFile, out aviStream, Avi.streamtypeVIDEO, 0); if(result != 0){ throw new Exception("Exception in AVIFileGetStream: "+result.ToString()); } VideoStream stream = new VideoStream(aviFile, aviStream); streams.Add(stream); return stream; }
public static bool CheckForVideo(KernelManager kernelManager) { if (_frame == null) return false; var i = _frame.Value / StepsPerPoint; if (i >= Frames.Count - 1) { _frame = null; _aviManager.Close(); RenderWindow.SetStatus("Finished video"); return false; } RenderWindow.SetStatus("Rendering frame " + _frame.Value + " of " + (Frames.Count - 1) * StepsPerPoint); var d0 = i == 0 ? Frames[0] : Frames[i - 1]; var d1 = Frames[i]; var d2 = Frames[i + 1]; var d3 = i == Frames.Count - 2 ? Frames[Frames.Count - 1] : Frames[i + 2]; var t = (float)(_frame.Value % StepsPerPoint) / StepsPerPoint; var config = CameraConfig.CatmullRom(d0, d1, d2, d3, t); var bmp = kernelManager.GetScreenshot(config, 720, 2); if (_frame.Value % 256 == 0 || _aviManager == null) { if (_aviManager != null) _aviManager.Close(); _videoStream = null; _aviManager = new AviManager(Ext.UniqueFilename("video", "avi"), false); } if (_videoStream == null) _videoStream = _aviManager.AddVideoStream(false, 25, bmp); else _videoStream.AddFrame(bmp); _frame = _frame.Value + 1; return true; }
public void makeAvi() { FrameRateForm dlg = new FrameRateForm(); if (DialogResult.OK == dlg.ShowDialog()) { int framelength = 0; SaveFileDialog saveAvi = new SaveFileDialog(); Bitmap bmp = null; if (saveAvi.ShowDialog() == DialogResult.OK) { bmp = (Bitmap)Image.FromFile(pathBox.Items[0].ToString()); AviManager manageAVIFile = new AviManager(saveAvi.FileName.ToString()+ ".avi", false); aviStream = manageAVIFile.AddVideoStream(true, dlg.Rate, bmp); Bitmap bitmap; for (framelength = 1; framelength < pathBox.Items.Count - 1; framelength++) { bitmap = (Bitmap)Bitmap.FromFile(pathBox.Items[framelength].ToString()); aviStream.AddFrame(bitmap); bitmap.Dispose(); } manageAVIFile.Close(); } } }
public void EndVideo() { if (isVideoCaptureRunning) { videoManager.Close(); if (isCompressed) { Compress(); } isVideoCaptureRunning = false; isCompressed = false; stream = null; videoManager = null; } }
/// <summary> /// /// </summary> public override void SetAnimation() { // Set canvas _canvas = _control.Canvas; // Avi if (_aviManager != null || _isLimit || !outputCheckBox.Checked) return; // Set AviManager. string filename = this.aviFileName.FileName; try { // Delete File. if (File.Exists(filename)) File.Delete(filename); // Create dir. if (!Directory.Exists(Path.GetDirectoryName(filename))) Directory.CreateDirectory(Path.GetDirectoryName(filename)); // Create Movie. _aviManager = new AviManager(filename, false); Bitmap bmp = new Bitmap(_canvas.PCanvas.Camera.ToImage(640, 480, _canvas.BackGroundBrush)); _stream = _aviManager.AddVideoStream(false, 10, bmp); } catch (Exception e) { Util.ShowErrorDialog(MessageResources.ErrCreateAvi + "\n" + e.Message); outputCheckBox.Checked = false; _stream = null; _aviManager = null; } }
//public void RunAnimation(List<Bitmap> images) //{ // //if (images != null && images.Count > 0) // //{ // String tempFileName = System.IO.Path.GetTempFileName() + ".avi"; // AviManager tempFile = new AviManager(tempFileName, false); // //tempFile.AddVideoStream(false, 10, images[0].Clone() as Bitmap); // tempFile.AddVideoStream(false, 24, Bitmap.FromFile(@"C:\temp\frames\frame_0.png") as Bitmap); // VideoStream stream = tempFile.GetVideoStream(); // for (int i = 1; i < 719; i++) // { // Bitmap bmp = Bitmap.FromFile(@"C:\temp\frames\frame_" + i + ".png") as Bitmap; // stream.AddFrame(bmp); // bmp.Dispose(); // } // //for (int n = 1; n < images.Count; n++) // //{ // // stream.AddFrame(images[n].Clone() as Bitmap); // //} // AviPlayer player = new AviPlayer(new EditableVideoStream(stream), this.pictureBox1, null); // player.Start(); // tempFile.Close(); // try { File.Delete(tempFileName); } // catch (IOException) { } // //} //} public void RunAnimation(VideoStream video) { }
/// <summary>Copy all frames into a new file</summary> /// <param name="fileName">Name of the new file</param> /// <param name="recompress">true: Compress the new stream</param> /// <returns>AviManager for the new file</returns> /// <remarks>Use this method if you want to append frames to an existing, compressed stream</remarks> public AviManager DecompressToNewFile(String fileName, bool recompress, out VideoStream newStream2) { AviManager newFile = new AviManager(fileName, false); this.GetFrameOpen(); Bitmap frame = GetBitmap(0); VideoStream newStream = newFile.AddVideoStream(recompress, frameRate, frame); frame.Dispose(); for(int n=1; n<countFrames; n++){ frame = GetBitmap(n); newStream.AddFrame(frame); frame.Dispose(); } this.GetFrameClose(); newStream2 = newStream; return newFile; }
private void ThreadRun(object arg) { if (!_running) { _running = true; while (!_exitEvent.WaitOne(0, false)) { IntPtr windowHandle = (IntPtr)arg; //Get the active window so we can translate it. Tree window = _windowCapture.CaptureWindowWithPixels(windowHandle, UsePrintWindow, false); if (window != null) { Prefab.Bitmap capture = window["capturedpixels"] as Prefab.Bitmap ; System.Drawing.Bitmap bmp = _pool.GetInstance(capture.Width, capture.Height); Bitmap.ToSystemDrawingBitmap(capture, bmp); // Get Window features Win32.WINDOWINFO windowinfo = new Win32.WINDOWINFO(true); Win32.GetWindowInfo(windowHandle, ref windowinfo); // Save as png image String filename = string.Format("{0}_f{1:D4}.png", _saveLoc.Substring(0, _saveLoc.Length - 4), frame_num); bmp.Save(@filename, ImageFormat.Png); frame_num++; if (_videoStream == null) { _videoStream = _aviManager.AddVideoStream(false, 20, bmp); } else _videoStream.AddFrame(bmp); _pool.ReturnInstance(bmp); } //Let's not melt our processor ;) Thread.Sleep(50); } _running = false; _aviManager.Close(); } }
public void StartVideo(String filePath, int frameRate, int width, int height, System.Drawing.Imaging.PixelFormat pixelFormat, int bytesPerPixel, bool isCompressed) { if (isVideoCaptureRunning || isCompressionRunning) { throw new Exception("Another video is currently being recorded or processed"); } compressThread = null; this.isCompressed = isCompressed; GetVideoFileNames(filePath, out this.finalFilePath, out this.tempFilePath); isVideoCaptureRunning = true; isCompressionRunning = false; String videoFilePath = finalFilePath; if (isCompressed) { videoFilePath = tempFilePath; } videoManager = new AviManager(videoFilePath, false); stream = videoManager.AddVideoStream(false, frameRate, width * height * bytesPerPixel, width, height, pixelFormat); }
/// <summary>Add an empty video stream to the file</summary> /// <remarks>Compresses the stream without showing the codecs dialog</remarks> /// <param name="compressOptions">Compression options</param> /// <param name="frameRate">Frames per second</param> /// <param name="firstFrame">Image to write into the stream as the first frame</param> /// <returns>VideoStream object for the new stream</returns> public VideoStream AddVideoStream(Avi.AVICOMPRESSOPTIONS compressOptions, double frameRate, Bitmap firstFrame) { VideoStream stream = new VideoStream(aviFile, compressOptions, frameRate, firstFrame); streams.Add(stream); return stream; }
/// <summary>Add an empty video stream to the file</summary> /// <param name="isCompressed">true: Create a compressed stream before adding frames</param> /// <param name="frameRate">Frames per second</param> /// <param name="firstFrame">Image to write into the stream as the first frame</param> /// <returns>VideoStream object for the new stream</returns> public VideoStream AddVideoStream(bool isCompressed, double frameRate, Bitmap firstFrame){ VideoStream stream = new VideoStream(aviFile, isCompressed, frameRate, firstFrame); streams.Add(stream); return stream; }
public void Open(string file) { lock (this) { _aviManager = new AviManager(file, true); _videoStream = _aviManager.GetVideoStream(); _videoStream.GetFrameOpen(); _currentFrame = 0; _frameBuffer.Clear(); } _threadFillBuffer = new Thread(this.FillBuffer) {Priority = ThreadPriority.Highest}; _threadFillBuffer.Start(); }
/// <summary>Add an empty video stream to the file</summary> /// <param name="isCompressed">true: Create a compressed stream before adding frames</param> /// <param name="frameRate">Frames per second</param> /// <param name="frameSize">Size of one frame in bytes</param> /// <param name="width">Width of each image</param> /// <param name="height">Height of each image</param> /// <param name="format">PixelFormat of the images</param> /// <returns>VideoStream object for the new stream</returns> public VideoStream AddVideoStream(bool isCompressed, double frameRate, int frameSize, int width, int height, PixelFormat format){ VideoStream stream = new VideoStream(aviFile, isCompressed, frameRate, frameSize, width, height, format); streams.Add(stream); return stream; }
//child-avi public void InitRecordingToolsAvi(Bitmap bmp, int AviFrameRate) { if (aviManager != null) { aviManager.AddVideoStream(aviCompressOption, AviFrameRate, bmp); vidStream = aviManager.GetOpenStream(0); } }
/// <summary>Paste a number of frames from another video stream into this stream</summary> /// <param name="sourceStream">Stream to copy from</param> /// <param name="copyPosition">Index of the first frame to copy</param> /// <param name="pastePosition">Where to paste the copied frames</param> /// <param name="length">Count of frames to paste</param> public void Paste(VideoStream sourceStream, int copyPosition, int pastePosition, int length) { Paste(sourceStream.StreamPointer, copyPosition, pastePosition, length); }
private void CloseMovie() { if (_aviManager != null) { _stream = null; _aviManager.Close(); _aviManager = null; } }
public VideoStreamRoadControl(VideoStream videoStream) { InitializeComponent(); VideoStream = videoStream; }
/// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary> int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) { Console.WriteLine("BufferCB " + DateTime.Now.Millisecond + " pbtime " + SampleTime); framecount++; videopos = startlogtime.AddSeconds(SampleTime); trackBar_mediapos.Value = (int) SampleTime; // The buffer should be long enought if (BufferLen <= m_stride*m_videoHeight) { // Copy the frame to the buffer // CopyMemory(m_handle, pBuffer, m_stride * m_videoHeight); m_handle = pBuffer; } else { throw new Exception("Buffer is wrong size"); } try { Console.WriteLine("1 " + DateTime.Now.Millisecond); //ip = this.GetBitMap(); image = new Bitmap(m_videoWidth, m_videoHeight, m_stride, PixelFormat.Format24bppRgb, m_handle); Console.WriteLine("1a " + DateTime.Now.Millisecond); image.RotateFlip(RotateFlipType.RotateNoneFlipY); Console.WriteLine("1b " + DateTime.Now.Millisecond); hud1.HoldInvalidation = true; hud1.opengl = true; hud1.bgimage = image; hud1.streamjpgenable = true; if (fullresolution) { hud1.Width = image.Width; hud1.Height = image.Height; } Console.WriteLine("1c " + DateTime.Now.Millisecond); hud1.Refresh(); Console.WriteLine("1d " + DateTime.Now.Millisecond); Bitmap bmp = (Bitmap) hud1.objBitmap.Clone(); // bmp.Save(framecount+".bmp"); Console.WriteLine("1e " + DateTime.Now.Millisecond); if (newStream == null) { //double frate = GetFrameRate(txtAviFileName.Text); double frate = Math.Round(10000000.0/m_avgtimeperframe, 0); newStream = newManager.AddVideoStream(true, frate, bmp); } Console.WriteLine("2 " + DateTime.Now.Millisecond); addframe(bmp); lock (avienclock) { // System.Threading.ThreadPool.QueueUserWorkItem(addframe, bmp); } Console.WriteLine("3 " + DateTime.Now.Millisecond); } //System.Windows.Forms.CustomMessageBox.Show("Problem with capture device, grabbing frame took longer than 5 sec"); catch (Exception ex) { Console.WriteLine("Grab bmp failed " + ex.ToString()); } return 0; }
public void Stop() { Debug.WriteLine("Stopping..."); if (aviManager != null) { aviManager.Close(); } else { Debug.WriteLine("aviManager is null. Cannot close."); } aviManager = null; aviStream = null; Sensor.ColorStream.Disable(); if (OnStop != null) OnStop(null); Debug.WriteLine("Stopped."); }