AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Can't record full screen using FFMEG Video File Writer - C#

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Can't record full screen using FFMEG Video File Writer - C#

Postby DSZ » Tue Apr 02, 2019 7:32 am

My app need to record entire screen as video. For that I have installed
AForge.Video.FFMPEG

and did like below.
Now I can record the screen. But some bottom area and right end area of screen is missing. Can anyone suggest what causes the issue?
I want to record the entire screen.

SystemInformation.VirtualScreen

is used to calculate screen size. it is getting as 1536*864
Code: Select all
private ScreenCaptureStream _streamVideo;
  private VideoFileWriter _Screenwriter;
  private Rectangle _screenArea;
  private bool _isScreenRecording;
  private int _Screenwidth;
  private int _Screenheight;
  public RecordVideo()
    {
        InitializeComponent();
        this._Screenwriter = new VideoFileWriter();
        this._Screenwidth = SystemInformation.VirtualScreen.Width;
        this._Screenheight = SystemInformation.VirtualScreen.Height;
        this._isScreenRecording = false;
        this._screenArea = Rectangle.Empty;
      }
private void btn_startRecord_Click(object sender, EventArgs e)
    {
        try
        {       
        if (btn_screenRecord.Text == "Record")
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                _isScreenRecording = true;
                this.StartRecScreen(fbd.SelectedPath);
            }
        }
        else
        {
            _isScreenRecording = false;
            btn_screenRecord.Text = "Record";
            MessageBox.Show(@"Recorded !");
        }
        }
        catch (Exception EX)
        { MessageBox.Show(EX.Message); }
    }

private void StartRecScreen(string path)
    {
       btn_screenRecord.Text = "Stop";
       this.SetScreenArea();
      _isRecording = true;
       string fullName = string.Format(@"{0}\{1}_{2}.mp4", path, "Record_", DateTime.Now.ToString("d_MMM_yyyy_HH_mm_ssff"));

            // Save File option
            _Screenwriter.Open(
                fullName,
                this._Screenwidth,
                this._Screenheight,
                10, VideoCodec.MPEG4, 1000000);
            // create screen capture video source
            this._streamVideo = new ScreenCaptureStream(this._screenArea);

            // set NewFrame event handler
            this._streamVideo.NewFrame += new NewFrameEventHandler(this.video_NewScreenFrame);

            // start the video source
            this._streamVideo.Start();

    }
    private void video_NewScreenFrame(object sender, NewFrameEventArgs eventArgs)
    {
        if (this._isScreenRecording)
        {             
            this._Screenwriter.WriteVideoFrame(eventArgs.Frame);             
        }
        else
        {             
            _streamVideo.SignalToStop();             
            _Screenwriter.Close();
        }
    }

    private void SetScreenArea()
    {
        // get entire desktop area size
        foreach (Screen screen in Screen.AllScreens)
        {
            this._screenArea = Rectangle.Union(_screenArea, screen.Bounds);
        }
    }
Attachments
fullscreen.PNG
Screen I'm trying to record
fullscreen.PNG (88.81 KiB) Viewed 854 times
Resulted Screen.PNG
Resulted Screen.PNG (99.38 KiB) Viewed 854 times
Last edited by DSZ on Tue Apr 02, 2019 8:53 am, edited 2 times in total.
DSZ
 
Posts: 15
Joined: Mon Feb 25, 2019 7:06 am

Re: Can't record full screen using FFMEG Video File Writer -

Postby andrew.kirillov » Tue Apr 02, 2019 8:10 am

DSZ wrote:it is getting as 1536*864

Do you get smaller screen size than expected ? Or do you get the right size, but some areas are simply not captured (blank) ?
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Can't record full screen using FFMEG Video File Writer -

Postby DSZ » Tue Apr 02, 2019 8:48 am

The recorded video is smaller screen size than expected. it covers left end of screen and top of screen correctly. but bottom portion and right end portion are not showing fully
DSZ
 
Posts: 15
Joined: Mon Feb 25, 2019 7:06 am

Re: Can't record full screen using FFMEG Video File Writer -

Postby andrew.kirillov » Tue Apr 02, 2019 9:18 am

You can do few tests to find where it may go wrong.

1) Just use video file writer and save some images of big size (your screen resolution) and see it you get expected result. Just create few dummy images and save. This will check if video writing is fine.

2) Use screen capture class now, but hard code screen area to capture (you can check manually your screen resolution). This will check if capturing screen is fine.

If both above work fine, then there must be something in the way screen size is calculated. Check that the size you calculate matches screen resolution you've set.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Can't record full screen using FFMEG Video File Writer -

Postby DSZ » Tue Apr 02, 2019 11:31 am

when trying with images it works with 1536 *864.

Code: Select all
  private void StartTakeSnapshot()
        {
            Rectangle bounds = Screen.FromControl(this).Bounds; //1536*864

            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    //Add screen to bitmap:
                    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                }
                //Save screenshot:
                string name = tempPath + "//screenshot-" + fileCount + ".png";
                bitmap.Save(name, ImageFormat.Png);
                inputImageSequence.Add(name);
                fileCount++;

                //Dispose of bitmap:
                bitmap.Dispose();
            }

        }


But when using ScreenCaptureStream have this issue.
this._streamVideo = new ScreenCaptureStream(_screenArea); scren area gets as (0,0,1536,864) since it is a rectangle.
Have any idea why this happens?
Last edited by DSZ on Tue Apr 02, 2019 5:18 pm, edited 1 time in total.
DSZ
 
Posts: 15
Joined: Mon Feb 25, 2019 7:06 am

Re: Can't record full screen using FFMEG Video File Writer -

Postby andrew.kirillov » Tue Apr 02, 2019 12:27 pm

DSZ wrote:this._streamVideo = new ScreenCaptureStream(_screenArea); scren area gets as (0,0,1563,864) since it is a rectangle.
Have any idea why this happens?

So you have it as 1563x864 instead of 1536x864? Or what?

_screenArea is something you set using whatever approach. If it is not the rectangle you want, then need to look at how it is set.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to AForge.NET Framework