Click here to Skip to main content
14,267,930 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a ffmpeg class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

namespace Desktop_Recorder
{
    class Ffmpeg
    {
        Process process;

        public void Start(string FileName, int Framerate)
        {
            process = new System.Diagnostics.Process();
            process.StartInfo.FileName = @"D:\ffmpegx86\ffmpeg.exe"; // Change the directory where ffmpeg.exe is.  
            process.EnableRaisingEvents = false;
            process.StartInfo.WorkingDirectory = @"D:\ffmpegx86"; // The output directory  
            process.StartInfo.Arguments = @"-f gdigrab -framerate" + Framerate + "-video_size 1920x1080 -offset_x 240 -offset_y 450 -i desktop -preset ultrafast -pix_fmt yuv420p" + FileName;
            process.Start();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            Close();
        }

        public void Close()
        {
            process.Close();
        }
    }
}


In the arguments i'm setting the location in the desktop to record:

-offset_x 240 -offset_y 450


But now i want also to set the width and height of what to record.
Like a rectangle. I want to record a video inside a rectangle.
For example: The rectangle is at location 10,10 and the rectangle size is: 20,20,20,20
So i want to record in the desktop only the area inside the rectangle.

In Form1 i did in the constructor:

Ffmpeg fpeg = new Ffmpeg();
            fpeg.Start("test.mp4", 24);


Then i'm creating a rectangle:

private void TransparentControl1_Paint(object sender, PaintEventArgs e)
        {            
                using (var pen = new Pen(this.ForeColor, 70))
                {
                    e.Graphics.DrawRectangle(pen, 0, 0, this.transparentControl1.Width - 1, this.transparentControl1.Height - 1);
                }
        }


Then in mouse move event i'm getting the form1 location and size: that is the rectangle.


private void TransparentControl1_MouseMove(object sender, MouseEventArgs e)
        {
            Point location = new Point(this.Location.X, this.Location.Y);
            Size size = new Size(this.Width, this.Height);
        }


What i want to do is to record the video in real time inside the rectangle area only.
Not once but in real time so if i move the form1(rectangle) around it will keep record only the area inside the form1(rectangle).

What I have tried:

What i have tried is described in the problem.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100