Exemplo n.º 1
0
        public SaveResult Initialize(string _filepath, double _interval, Size _FrameSize)
        {
            // Open the recording context and start the recording thread.
            // The thread will then wait for the first frame to drop in.

            // FIXME: The FileWriter will currently only use the original size due to some problems.
            // Most notably, DV video passed into 16:9 (720x405) crashes swscale().
            // TODO: Check if this is due to non even height.
            VideoInfo vi = new VideoInfo {
                OriginalSize = _FrameSize
            };
            SaveResult result = m_VideoFileWriter.OpenSavingContext(_filepath, vi, _interval, false);

            if (result == SaveResult.Success)
            {
                m_bInitialized     = true;
                m_bCaptureThumbSet = false;
                m_WorkerThread.Start();
            }
            else
            {
                try
                {
                    m_VideoFileWriter.CloseSavingContext(false);
                }
                catch (Exception exp)
                {
                    // Saving context couldn't be opened properly. Depending on failure we might also fail at trying to close it again.
                    log.Error(exp.Message);
                    log.Error(exp.StackTrace);
                }
            }

            return(result);
        }
        private void bgWorkerDualSave_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                dualSaveProgressBar.Close();
                dualSaveProgressBar.Dispose();

                if (!dualSaveCancelled && (int)e.Result != 1 && videoFileWriter != null)
                    videoFileWriter.CloseSavingContext((int)e.Result == 0);
            }
            catch (Exception exception)
            {
                log.ErrorFormat("Error while completing dual save. {0}", exception);
            }

            NotificationCenter.RaiseRefreshFileExplorer(this, false);
        }
Exemplo n.º 3
0
        public void FrameGrabbed()
        {
            //----------------------------------------------
            // NOTE : This method is in the GRABBING thread,
            // NO UI calls can be made directly from here.
            // must use BeginInvoke at some point.
            //----------------------------------------------

            // The frame grabber has just pushed a new frame to the buffer.

            // Consolidate this real-time frame locally.
            Bitmap temp = m_FrameBuffer.ReadFrameAt(0);

            // Copy the frame over if size change is needed.
            if (!temp.Size.Equals(m_ImageSize))
            {
                m_MostRecentImage = new Bitmap(m_ImageSize.Width, m_ImageSize.Height);
                Graphics g = Graphics.FromImage(m_MostRecentImage);

                Rectangle  rDst = new Rectangle(0, 0, m_MostRecentImage.Width, m_MostRecentImage.Height);
                RectangleF rSrc = new Rectangle(0, 0, temp.Width, temp.Height);
                g.DrawImage(temp, rDst, rSrc, GraphicsUnit.Pixel);
            }
            else
            {
                m_MostRecentImage = temp;
            }

            // Ask a refresh. This could also be done with a timer,
            // but using the frame grabber event is convenient.
            if (!m_bPainting)
            {
                m_bPainting = true;
                m_Container.DoInvalidate();
            }

            // We also use this event to commit frame to disk during saving.
            // However, it is what is drawn on screen that will be pushed to the file,
            // not the frame the device just grabbed.
            if (m_bIsRecording)
            {
                // Is it necessary to make another copy of the frame ?
                Bitmap     bmp = GetFlushedImage();
                SaveResult res = m_VideoFileWriter.SaveFrame(bmp);

                if (res != SaveResult.Success)
                {
                    log.Error("Error while saving frame to file.");
                    DisplayError(res);
                    bmp.Dispose();
                    m_bIsRecording = false;
                    m_VideoFileWriter.CloseSavingContext(true);

                    // TODO: remove broken file.
                }
                else
                {
                    if (!m_bCaptureThumbSet)
                    {
                        m_CurrentCaptureBitmap = bmp;
                        m_bCaptureThumbSet     = true;
                    }
                    else
                    {
                        bmp.Dispose();
                    }
                }
            }
        }