Ejemplo n.º 1
0
 private void btnGo_Click( object sender, EventArgs e ) {
     if ( _recorder.Recording ) {
         _recorder.Stop();
         SetR( false );
     }
     else {
         SetR(true);
         _settings = new RecordSettings(
             outputPath: txtPath.Text,
             captureRectangle: ( (ScreenInfo)cmbScreen.SelectedItem ).Rect,
             fps: (int)nudFramerate.Value,
             interval: (int)nudFreq.Value,
             codec: (VideoCodec)cmbFormat.SelectedItem,
             bitrate: (int)budBitrate.Value << 20,
             splitInterval: chkSplit.Checked?(int?)(int)nudSplitInterval.Value :null,
             onFrameWritten: (a)=>BeginInvoke( (Action)(()=>lblTime.Text = string.Format( "Elapsed :{0}", a.ToString("g") )) )
         );
         _recorder.Start(
             _settings
         );
     }
 }
Ejemplo n.º 2
0
        private void StartInternal( RecordSettings settings ) {
            try {
                _stopwatch = _stopwatch ?? new Stopwatch();
                _stopwatch.Reset();
                _stopwatch.Start();
                StopWaiter.Reset();
                if ( !Directory.Exists( settings.OutputPath ) ) Directory.CreateDirectory( settings.OutputPath );
                while ( Recording ) {
                    var outfile = Path.Combine( settings.OutputPath, DateTime.Now.ToFileTime().ToString() + ".avi" );
                    using (var outstream = new VideoFileWriter()) {
                        var sourceRect = settings.CaptureRectangle;
                        var w = sourceRect.Width;
                        var h = sourceRect.Height;

                        outstream.Open(
                            outfile,
                            w,
                            h,
                            settings.Fps,
                            settings.Codec,
                            settings.Bitrate );

                        var mpf = settings.SplitInterval * 60000 / settings.Interval;
                        using ( var bmp = new Bitmap( w, h ) ) {
                            using ( var gr = Graphics.FromImage( bmp ) ) {
                                for ( var i = 0; (mpf==null||i < mpf) && Recording; i++ ) {
                                    try {
                                        gr.CopyFromScreen( sourceRect.X, sourceRect.Y, 0, 0, sourceRect.Size );
                                        PreprocessFrame( gr, settings );
                                        gr.Flush();
                                        outstream.WriteVideoFrame( bmp );
                                        settings.OnFrameWritten?.Invoke( _stopwatch.Elapsed );
                                    }
                                    catch { }
                                    Thread.Sleep( settings.Interval );
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception ex) {
                //global
            }
            finally {
                _stopwatch?.Stop();
                StopWaiter.Set();
            }
        }
Ejemplo n.º 3
0
 public void Start( RecordSettings settings ) {
     var timer = new Timer();
     if (Recording)
         throw new InvalidOperationException("Recording is already started");
     Recording = true;
     new Thread( () => StartInternal(settings) ).Start();
 }
Ejemplo n.º 4
0
 private void PreprocessFrame( Graphics gr, RecordSettings settings ) {
     if ( !settings.Private ) return;
     gr.Clear( Color.Black );
     gr.Flush();
 }