예제 #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);
        }
예제 #2
0
        private void bgWorkerDualSave_DoWork(object sender, DoWorkEventArgs e)
        {
            // This is executed in Worker Thread space. (Do not call any UI methods)
            log.Debug("Saving side by side video.");

            int threadResult = 0;

            // Get first frame outside the loop to set up the saving context.
            long   currentTime = 0;
            Bitmap composite   = GetCompositeImage(currentTime);

            log.DebugFormat("Composite size: {0}.", composite.Size);

            VideoInfo info = new VideoInfo
            {
                ReferenceSize = composite.Size
            };

            string formatString = FilenameHelper.GetFormatString(dualSaveFileName);

            SaveResult result = videoFileWriter.OpenSavingContext(dualSaveFileName, info, formatString, fileFrameInterval);

            if (result != SaveResult.Success)
            {
                e.Result = 2;
                return;
            }

            videoFileWriter.SaveFrame(composite);
            composite.Dispose();

            while (currentTime < commonTimeline.LastTime && !dualSaveCancelled)
            {
                currentTime += commonTimeline.FrameTime;

                if (bgWorkerDualSave.CancellationPending)
                {
                    threadResult      = 1;
                    dualSaveCancelled = true;
                    break;
                }

                composite = GetCompositeImage(currentTime);
                videoFileWriter.SaveFrame(composite);
                composite.Dispose();

                int percent = (int)((double)currentTime * 100 / commonTimeline.LastTime);
                bgWorkerDualSave.ReportProgress(percent);
            }

            if (!dualSaveCancelled)
            {
                threadResult = 0;
            }

            e.Result = threadResult;
        }
예제 #3
0
        public void StartRecording(string filepath)
        {
            // Start recording.
            // We always record what is displayed on screen, not what is grabbed by the device.

            // Restart capturing if needed.
            if (!m_FrameGrabber.IsGrabbing)
            {
                m_FrameGrabber.StartGrabbing();
            }

            // Open a recording context.
            int        interval = 40;
            InfosVideo iv       = new InfosVideo();

            // The FileWriter will currently only use the original size due to some problems.
            // Most notably, DV video passed into 16:9 (720x405) crashes swscale().
            iv.iWidth  = m_FrameGrabber.FrameSize.Width;
            iv.iHeight = m_FrameGrabber.FrameSize.Height;

            if (m_FrameGrabber.FramesInterval > 0)
            {
                // Hack. For interlaced video, we get the fields interval, which is half the frame interval.
                interval = m_FrameGrabber.FramesInterval * 2;
            }

            SaveResult result = m_VideoFileWriter.OpenSavingContext(filepath, iv, interval, false);

            if (result == SaveResult.Success)
            {
                // The frames will be pushed to the file upon receiving the FrameGrabbed event.
                m_bCaptureThumbSet = false;
                m_bIsRecording     = true;
            }
            else
            {
                m_VideoFileWriter.CloseSavingContext(false);
                m_bIsRecording = false;
                DisplayError(result);
            }
        }