Click here to Skip to main content
15,867,686 members
Articles / Multimedia / Video
Tip/Trick

Screen Recorder

Rate me:
Please Sign up or sign in to vote.
3.33/5 (28 votes)
4 Oct 2016CPOL 61.3K   28   16
Create a screen recorder using C#

Introduction

In this tip, we create a customized screen recorder using C#.NET.

Background

At work, we wanted a screen recorder to record the procedure. Unfortunately, we don't have any screen recorder. So I developed a screen recorder in C# to record our screen.

Using the Code

At first, create a source and install Accord.Video.FFMPEG from nuget library.

Image 1

Screen recorder is created by a timer and VideoFileWriter.

First of all, initialize a timer control and assign properties to the control. Then, create a tick event to that timer .

C#
timer1 = new Timer();
timer1.Interval = 20;
timer1.Tick += timer1_Tick;
vf = new VideoFileWriter();
vf.Open("Exported_Video.avi", 800, 600, 25, VideoCodec.MPEG4, 1000000);

Create a start button to start the timer.

C#
private void button1_Click(object sender, EventArgs e)
{
    timer1.Start();
}

In the timer tick event, create a bitmap image from the size of VideoFileWriter and capture screen and write it to bitmap image. Then, write the image to VideoFileWriter.

C#
private void timer1_Tick(object sender, EventArgs e)
{
    bp = new Bitmap(800, 600);
    gr = Graphics.FromImage(bp);
    gr.CopyFromScreen(0, 0, 0, 0, new Size(bp.Width, bp.Height));
    pictureBox1.Image = bp;
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    vf.WriteVideoFrame(bp);
}

Create a stop button to stop the timer and save the file.

C#
private void button2_Click(object sender, EventArgs e)
{
    timer1.Stop();
    vf.Close();
}

License

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


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerThe real solution is just a one-liner Pin
Sergey Alexandrovich Kryukov4-Jan-21 11:59
mvaSergey Alexandrovich Kryukov4-Jan-21 11:59 
Why? Everything is already done, in a much more flexible and contemporary way. The usage would be just one line, for example:
ffmpeg
    -f dshow -i audio="Stereo Mix (Realtek Audio)" ^
    -f gdigrab -itsoffset 00:00:0.6 -i desktop -c:v libx264rgb ^
        -framerate 24 -crf 20 -preset ultrafast ^
    output-file.mp4

For more detail:
Video Screen Capture with Audio

Thank you.
—SA
Sergey A Kryukov

QuestionAudio not coming in Recorded video Pin
LekshmiM25-Sep-20 6:32
LekshmiM25-Sep-20 6:32 
Questionhalf-baked idea Pin
bechemot9930-Mar-20 17:14
bechemot9930-Mar-20 17:14 
QuestionCreates one frame and stops Pin
Gerry Lindsay19-Nov-19 4:14
Gerry Lindsay19-Nov-19 4:14 
QuestionThrows "Bad Parameter Passed" sometimes Pin
jayesh baviskar13-May-18 17:48
jayesh baviskar13-May-18 17:48 
AnswerRe: Throws "Bad Parameter Passed" sometimes Pin
Laurent Chougrani2-Dec-19 23:24
Laurent Chougrani2-Dec-19 23:24 
AnswerRe: Throws "Bad Parameter Passed" sometimes Pin
Apopka_Pilot10-Dec-19 4:01
Apopka_Pilot10-Dec-19 4:01 
GeneralThank you Pin
kjun091816-Apr-18 21:36
kjun091816-Apr-18 21:36 
QuestionNo have VB.NET source? Pin
Member 137584624-Apr-18 0:54
Member 137584624-Apr-18 0:54 
Questionneed help in implementing this code Pin
Ahmad_Mustafa26-Apr-17 20:43
Ahmad_Mustafa26-Apr-17 20:43 
QuestionCode? Pin
DumpsterJuice10-Oct-16 6:09
DumpsterJuice10-Oct-16 6:09 
GeneralMy vote of 1 Pin
Member 44352486-Oct-16 14:01
Member 44352486-Oct-16 14:01 
GeneralRe: My vote of 1 PinPopular
E. Scott McFadden6-Oct-16 16:14
professionalE. Scott McFadden6-Oct-16 16:14 
QuestionAnd where is your contribution? Pin
Sergey Alexandrovich Kryukov4-Jan-21 5:30
mvaSergey Alexandrovich Kryukov4-Jan-21 5:30 
QuestionBadImageFormat Pin
Babba725-Oct-16 5:15
Babba725-Oct-16 5:15 
QuestionSubject line misspelled. Pin
OriginalGriff4-Oct-16 23:21
mveOriginalGriff4-Oct-16 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.