Create a Screen Recorder in C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this c sharp tutorial on how to make a screen recorder and just start off i will say i am not actually recording this video on a screen recorder that i made i am just using OBS and that's because the screen recorder that we're going to end up with is it's going to be a functioning screen recorder it's going to have audio and all that but it's not going to be you know the most perfect screen recorder out there so if you're looking to make like you know like something like OBS this isn't really the tutorial but rather this is just a basic tutorial on how to get a functioning screen recorder to work and basically all of what goes into making a screen recorder and so i just want to say that right off the bat so anyways without out of the way we're actually going to need to install a new get package in order to get this to work so the new get package that we're going to need to install is something called ffmpeg and it's a very helpful tool that basically helps us you know manipulate audio and stuff so i'm pretty sure what is it here I think something here now here just manage NuGet packages and then we want to bore house for I believe it is called we want to get a chord video ffmpeg and so I'm gonna get this one right here and then we just want to hit install then we want hit that I accept and then will automatically install it for you something that c-sharp is very good at doing and so once that's installed you actually also need one other thing you actually also need to actually download ffmpeg and hook it up to your you need to hook it up to your pass kind of like if you've ever installed Eclipse you kinda have to do the same thing where you go into environmental variables and hook it up to your paths I'll link a video down in the description where you can watch how to do that Bob just not gonna go over that just because I want to get right into making the actual screen recorder so once you download that and get that all hooked up then you can come back and we'll be ready so basically we don't really need to do anything with the form yet I kind of want to start off just by building the actual screen recorder so I'm going to do is I'm going to create a class that's basically just going to be called our screen recorder class here so I'll just call this a screen recorder class and yeah so this is just going to encompass everything which probably is not the best coding practice to get into but just because I want to keep it all in one class because we're only making one screen recorder here I'm just going to be doing it this way so okay so once you have this all created we need to do a few imports so first what I like to do is well I like to just import everything that we need from the form so that way we can manipulate forms as we need them so we're just going to be saying something like we need to be using system dot Diagnostics I'm gonna be using system dot drawing we need to be using system drawing dot imaging we need to be using what else oh we also we're going to add a time feature to this so we need for that we need system dot run time dot inter interrupt services and then finally we go down here and import our F of M pace we're so using a cord dot video ffmpeg here and so once we got all that in these are all the things that we're going to be using throughout this class here so the first thing that we can go ahead and do is before defining our constructor we just need a few variables here that are going to carry out throughout the throughout the class so the first thing we say is we're gonna create a private rectangle called bounds here and the bounds variable here is just going to get the bounds of the screen that happens to be you know running this and so yeah so then also we going to do is we get a private string going called output path because we want the user to be able to decide where the final video is going to be located so this is there's actually going to be an extremely important variable that we'll see as we move through this and then we're also going to do a private string called our temporary path here and this is going to be the path that we create because basically how the screen recorder is going to be working is we're going to be creating a temporary folder on the on a data drive on somewhere on the hard drive and we're going to be taking just a lot of different screenshots of the screen and we're going to be storing them in a temporary folder and then after you know we're done recording we're just going to take every screenshot turn it into a video you know merge it with the audio and then we're going to get rid of the screenshots and so we need this temporary path here to keep track of the location of where all those screenshots are it'll make a lot more sense when we once we actually start using it and then we're going to create an integer here called file count this is going to be for our screenshots just so we have something to give each screenshot screenshot a unique identifier and then finally we're gonna create a a private list of string I cannot spell today oh my god sorry about that so we create a private list of string it called input image sequence which will be mixed with new list of string and basically this is going to store it'll store the names of all of the files all the screenshots that we create and so that way we have access to them when we're putting on the video once again it all make more sense once you actually accusing us I'll just go ahead and define these called video variables here okay the next thing we're going to need is we're going to need our file variables so I'll define that file variables and for the final variables we're going to just say private string audio name this is going to be what we're going to call the audio file that we create because we're actually going to be originally creating a separate video and separate audio file and then we're going to be merging them together at the end and that's what ffmpeg is for you know the actual downloaded version that you hook up to your environmental variables and our add to your path whatnot so we're just gonna call this mic twelve you can call it anything you want for this videos purpose make sure it's a dot WAV file because that r dot wav file because that's what i will that's what I'll be doing and they'll also do a string called a video name here and I'll just call this video and we're gonna be using the file type of mp4 just because that is the most efficient way to do it in with the least taking up the least amount of space and then final we're also going to create the file the final name and this is actually something I like to allow the user to edit so that's why this is a variable here and so this will be final I guess final video and before so the user does not want to edit this name it'll just be called final video mp4 but later on we're going to allow the user to edit it and then finally we're just going to also create our time variable here we just want to get the elapsed time so we're going to create a stopwatch called watch will she'll be equal to just a new stopwatch just like that and then for our audio there's actually a specific way that we get audio in c-sharp so I'm going to go ahead and just call our audio variables here and basically what we do is want to create a public static class called native methods here and what native methods is going to do is it's actually just going to be importing from a certain dll file and creating a method that will run I'm going to copy and paste it in real quick so you could actually just look it up so basically like what I would do in this situation is I would just look up you know so c-sharp record audio and then you can go in here and then these are the two variables that we need right here and then we can just go ahead and paste those in there just like that C with program there's this magic tool called Google that we all use if we don't know something so yeah there you so just I'll link that down in the description so you can just paste that in there just because I don't want to type that all out and then once we have that I believe that will do it for all of the variables that we need and we can start writing some classes so I'm going to start off with the constructor as you know people normally do so we should call this the public screen recorder and this is going to take in two parameters the first parameter is going to be a rectangle which I'll just call B which will be bounce and then it's also just going to be making a string call which I'll call out path and and obviously the first thing that we want to do is we just want to say that our bounds variable I was crazy will it be and then our output path variable is equal to out path not output path make sure make sure you you get this right don't set out path equal to output path so maybe you don't want to name it up close but that's just the way I do and that's all it's going to do for now because we actually are going to do is we're going to create a separate method that is because something I want to do in the constructor is I want to have it when the variable screen recorder is called I want it to automatically create that temporary file on the hard drive basically and I'm gonna do that with a difference method so I'm gonna go down here and I'm gonna create a private void called creates temp folder down here and this is going to just take an a string called name so that way you can change the name of the temporary folder and the first thing is going to do is it's going to say if directory I think actually we're missing an import here because I think we need it yep we need to import using system io and then now we should be able to call this so if directory dot exists so if the directory that we are you know creating or no sorry what this is doing actually is we're going to be checking to see if the user has a certain directory so from my case on my computer I have a D Drive and I have a C Drive and so this is just going to be checking whether or not the user has a D Drive or C Drive because usually if people have D drives that's where they like to keep all their massive data at least that's the case for me and so this is where I'm gonna be storing it so if directory dot exists if the D Drive directory exists then what we're going to do is we're going to say then string path name is going to be equal to and some of you can do it c-sharp is if you want to insert a variable in a string just call the dollar sign and then inside the string we could say the D Drive and then put in brackets here the name of the variable so that's going to be the path name and then we're just going to say directory dot create directory path name and then we want to set the temp path equal to the path name that we just created there and then you know if they have something other than a D drive like they just have a C Drive then you can just go ahead and you the same thing except for the C Drive there just because everyone at least has a C Drive but some people have D drives and I personally like to keep all my mass data on my D Drive because my C Drive is you know almost full so once we have this method created we can actually come back up here to our constructor variable and we can just say create temp folder and I'm just going to create call this temp screenshots here and and so yes and now upon creating the screen recorder variable which we're going to do in our format this is where we're going to be implementing this class it's going to create a temporary folder that's going to store all the screenshots just like that okay and so after this the next thing that we're going to be creating is we need the thoughts of methods that will delete the screenshots basically because after because obviously we don't want to keep this temporary let's call a temporary folder for a reason so we don't want to keep it here so we're going to create a method called private void and this is going to be delete path and this is just going to taking a string called target directory just like that and in order so how we're going to do this is we're going to create a an array of strings here it's called a file which will be equal to directory dot get the files of the target directory so we want to get all the files that are in the target directory and then we also want to get the actual directory there's only one in this case but it's good just to make this a string just in case we want to expand this later on we want to say gets directories of the target directory just like that so we get every citizen not only do we want to delete the directory but we also want to delete all the files that are within the directory so every individual screenshot and so when we go down here is we could just say for each string file in files so for every file that exists in the directory all we want to do is first we have to change its attribute to file attribute normal and I'm not entirely sure why this is I am almost positive it has to do with the fact that the file is read-only and if the file is read-only then you're not allowed to edit it but basically what this will do this just allows you to delete the file so it'll set it from probably read-only to normal and then once this is done you can just say file dot not that you want to call the capital F file dot deletes and then we want to delete the lowercase photo just like that and so this will delete every single file that's in the directory at the end and then we also want to finally delete delete the path so actually we do this through two methods so we're just going to say for each string directory and directories we're just going to say we're just going to kind of call like a recursive function here and we're just going to delete the directory and then we're also just going to finally at the end say here directory dots deletes the target directory and then we just want to set this to false recursion okay so once we got that we actually also want to do a another delete function and what this is going to do is because as I mention at the beginning we're going to be creating two separate you know we're gonna be creating two separate video and audio files before merging them into one final and so we don't want to keep those separated video and audio files we want to get rid of them after we've merged them together and so what I just ended up calling this method ISM call this a private void called delete files except you know delete all the files except this one and this is going to taking a string called our target directory here and I guess I call it a target file and then string of the exception file here and so all this is going to do is we're going to create once again another string called files and that's going to be equal to the directory get files you probably know the drill at this point so target file or no actually I believe this is we do want to call this alright I guess it doesn't matter just matter I'll just keep it like this so well I'm just gonna say is we're gonna call another for each lips I'm going to say for each string file in files what we want to do here is I'm going to say if the file is not equal to the exception file so if the current iteration of a file is not equal to the exception files and we want to say file dot at your set attribute once again this is the thing that we have to do in order to allow Windows to let us delete it and then we're gonna say file attributes that's normal here so that's the first thing we do and then finally we're going to say file dot delete the current file just like that and so this was Lee every file except the file that we specify and we're going to specify little eat these two you know delete every file except this file except final name here just like that and so once we have these variables we're also going to create one more that's just kind of for you know cleanup purposes so we're going to call a private or another that should even be a public board actually excuse me a public for it called cleanup and this is going to happen so basically because we're creating the the temporary folder upon the screen recorder variable being called if the you know the program were to crash or the user would it just exit out of the program unexpectedly while still recording then all the screenshots would actually stay on the drive that they saved it the temporary file would not be deleted because you know we're only going to have the temper delete after the video is created and so we just want to have something that will in an extreme case if the program crashes we want to just make sure that all the temporary files do indeed get deleted and so how are you excuse me how we're gonna do that is with this public void called clean up so we're going to say if directory dot exists and temp path found pretty simple we just want to say delete path which is the you know the method we just create temp F so a pretty simple you know if the path exists then delete it and we're going to be implementing this more once we get to actually implementing the class so right now this method just needs to stand here as it currently does and then another so now we can actually start getting into more of the video related stuff and so the first thing I'm gonna do is I'm just gonna create a method there's gonna be another public void or actually a public string excuse me call gets eat laps and this is just going to return the elapsed time that the screen recorder has and if you remember we created a stopwatch object up here well as for this purpose called watch so I'm just gonna say is I'm just going to say return string dot format and this is a little fun to type in here excuse me we want to return the format of 0 D 2 which is you know position 0 two decimal places so yeah so 0 so this will return like hours and then we want to say 1 D 2 this will return seconds and then our minutes and then 2 D 2 and this will return seconds and so we just don't say watch dot e lap stop hours watch dot u lab stuff minutes and watch elapsed seconds here ok and so this will just allow us to keep track of the total recording time and this will actually help us when we get around to you know playing around with making sure the audio and video match up this will just allow you to you know look at the time of a video versus time that's on the screen reporters timer and this way you play around with like because we're going to be and because we're going to be using a timer here so you can end up playing with the with all those variables in the framerate and stuff like that so anyways now we can actually get into the good stuff here and so this is going to be the method that will end up recording the video and I know I'm gonna say you know recording is kind of in quotes because what is screen recording you know what actually is screen recording and basically all screen recording in this case is doing is this is going to be taking a lot of screenshots of the screen and so that's basically what our record video method is going to do is it's just going to create a screenshot and so that's why we have to run it on a timer here um so let's go and just play this so this is going to be a public void called record video here and actually I should probably keep up with the you know c-sharp just there's a you know thing in c-sharp where you keep the first letter capitalised and whatnot so there's gonna be a public void called record video it's not gonna take in any parameters and so the first thing we're gonna do is we're just gonna say watch dot start just so you know we don't forget that we're just going to start you know as soon as you hit we hit record we want to you know start keeping track of time and so now what we're going to do is we're going to actually be using using statements so the first using statement we're going to do is we're going to use a bitmap and we're gonna say using a bitmap just call the bitmap equal to a new bitmap which will be the size of bounce width and bounds dots height here and then within this using statement what we want to say is we're gonna say using graphics G equal to graphics dot from image nope from image and then of it's a bitmap okay so what are we doing here so basically we're creating a bitmap which is going to be equal to the bounds and whiff of this and then we're going to be creating a graphics variable here that is going to basically copy something to the bitmap so how we do that as we say G dot copy from screen a new point of bounds dots whoops bounce dot left's and then bounce dot top bounce that top and then we could just say a points dot empty here and then bounce dot size here whoops dot top okay and so I should not have these things after it okay so basically all this is doing is creating a screen shot of the screen during this current iteration of the void and that's the space is kind of like a standard way to do it and so once we have this screen shot all we have to do is we then have to save it because this is creating a bitmap and then it's adding a copy of the screen to the bitmap that we're creating with this using a statement and so genome and we're still within this using statement here what we're going to say is we're just going to create a string called name which is going to be equal to the temporary path plus screen shot the temporary path being the folder that we want to temporarily save screenshots do we reduce Crean shot - and then we're going to do the file count which is if you remember that's the variable that we created up here the file count and then we're also going to add a dot PNG so we're going to save each file as a PNG file and then how we actually you know relate this to the bitmap is we're going to say bitmap dot save and we're going to save this to the name and we're going to use an image format dot PNG just like that and then finally or another thing we want to do is we're going to say input image sequence dot add the name so we want to add this directory here to the image input sequence so that way we can keep track of every screenshot that is you know save then finally we want to do is we want to just increase file count just like that okay and then also don't forget to do bitmap dot dispose because you know when we get around to actually deleting the screenshots windows will not let you delete the file if you're technically using it unfortunately it's not Linux so you have to get rid of every bitmap after you're done using it and that's basically all there is to the record video method is is just creating a screenshot and it's saving it to the folder and it's also saving it to our array here okay so after that's done we're also going to be doing a variable called record audio this is a little bit more straightforward record audio here and record audio this is once again just kind of a standard way to do it so we're gonna call our native method class here and we're just going to call native methods dot hold on a second excuse me um I have it said oh I have to change this on the changes to just to record here and then native methods dots that's strange hold on a second let me I may have to make this a yes I have to make this public I was wondering why that wasn't working okay so now we should be able to call record so that okay sorry about that so so we want you call the record method that we created up here and we won't just want to say you know this is kind of also a default thing that you just find online so alias rec sound and then two blanks here then zero zero I'll put all this in the description as well just so you have this to type in and then we also want to say native methods dot record and then record wreck and I'm here zero zero so there's not really much to explain here this is just kind of a default way in the C sharp to record while using this here so once you have that in that's really all there is to recording the audio and then we can get into saving the audio and video and so we're going to create another private void and this is going to be a private void save video and this is going to take in a few parameters so this I'm taking an int called width and called height and an int called frame rate here and so basically let's say video is going to do is it's going to save the video to the final output location that we need it to and in order to do this what we have to do is we call another using statement and we're going to this is the first time we're going to be using our ffmpeg imports I'm gonna say using a whoops a video file writer and we're seeing call this VF writer oops VF and then writer here and that's gonna be equal to a just a new video file writer so using that which we call from our you know Accord ffmpeg library we're going to create so we're gonna open rather a video on the output path that the user specified plus two backslashes plus the video name that we specified above and as well we have to put in the width the height rain rates and then also the video codec and this is also very important and remember up here we defined this name the video name as video mp4 here so we have to save the video codec as a mpeg-4 just like that and so once the video is open we can begin to add each individual screenshot that we take with the record video method we can begin to just add that to the video file writers how we do that was you say or each string which we're going to call just image location in our image or in our input image sequence here so remember we added the name of every screenshot to this array here and so that's why we're calling this a string because we're just giving the name of the file which still exists at this point we have not deleted the file and so what we're going to do within this for loop is we're going to create a bitmap and we're just gonna call this image frame B just do the syntax of how this is going to work so we're gonna create a bitmap called image frame which is actually gonna be equal to it system dot dot drawing dots image dot from file and from the file of the image location here and we're going to say as a bitmap just like that so we're going to save that as a bitmap and then we can say call our VF writer and we can write a video frame here called image or image frame so I cannot spell image frame and so it's as simple as doing that to write an actual video frame and then finally we wanna say image frame dot dispose because it's a bitmap and we have to get rid of it and then after all this is done all we have to do is go down here and say a VF writer dot close after we're done and this is all there really is to adding screenshots to a video so this will create our video mp4 file that we called up here and so once we have this video to mp4 file we now need the mic dot wav file and so in order to do that we need to create a you know a save audio method and how we create a save audio method is once again it's kind of straight forward search we call a of public or this nation should we be a private void because we don't need to call it in our instantiation class private boy called save audio and once again there's kind of a standard way to do this so we're just gonna say string audio path is equal to save wreck sounds and then plus our output path plus two backslashes plus our audio name that we defined up here so this is just going to be the path that we're saving it to and this is kind of like a command that the native methods class is going to recognize here and so this will just save the audio as the audio name which we defined remember as Mike dot wave up here so it'll save it as this file here and then we're just gonna call native methods dot record audio path and then zero zero here and then as well as native methods dot record glows rec sound and then a blank here at zero zero just like that and oops I forgot there real okay so once again this is just kind of standard c-sharp that doesn't require much explanation and then the last thing that we need before we finally write the last method which will be the method that terminate that implements everything basically that we have been doing here the stop method we need one final private void and this is going to be the void that come finds the audio the video and audio now I'd say when researching this this actually took me the longest to figure out so this is going to create a string called video and then a screen called audios from sake in and so this is where you actually definitely need to have ffmpeg installed on your computer and hooked up to your path and because basically we're going to be doing is we're going to be creating a temporary command prompt app app and we're going to be executing the ffmpeg command on the command prompt and so in order to do this what we're going to do excuse me is I'm just going to define up here the string variable that the arguments because it's called arguments I guess I'll call this command so the string command I'm going to be using is equal to the dollar sign because we want to include variables in this command and the first thing we have to do is do slash C and basically this is just going to separate the the file name which I'll show you what that is in a second from the actual command and this will allow us to continuously see the command probe because I like to see command prompt while it's open so that way I can see if any errors are happening if you don't want to see this then you can you /k but it's kind of your choice I'm gonna do slash C and then I'm say if F MPEG which is you know the just to command - I and then we actually have to include quotes in here so how we include a quote is we're gonna do backslash quote here and we're going to within the quote we're going to put our video variable here and then we're going to do backslash quote just like that and so this will allow us to put the video in quotes and then we want to say - I again and we want to do the same thing backslash quote audio and then backslash quote and then we want to say - shortest and then final name here okay and so this is just basically a command that I found online that will combine an audio and a video files so we're going to be taking this here you know what if we pass in for video this year whatever we pass in for audio and then we're going to be saving it as the final name and the final name of course is going to be final video mp4 or whatever the user will change it to but we'll get there in a minute okay so that's going to be the command that we're executing and so in order to run this command what we're gonna do is we're going to create a variable called a process start info variable and we're just going to call the start NFL start info and that's just going to equal to a new so start info just like this and what we're going to do actually is we're going to be we're gonna be setting a bunch of things for it so I'm gonna say create no window is going to be equal to false because as I said I wanted to create a window whoops this needs to be a comma not whoops needs to be a comma create no window is equal to false and then we must say that the file name is going to be equal to cmd.exe whoops which is obviously you know the executable name of command prompt and then we want to say the working directory and this is very important is equal to the output path we want to make sure that CMD is running in the directory of the output path because this command only works if these you know if everything that odd the video the audio and the final name if those are all in the same directory so we want to make sure we're working in the same directory and then finally in order the command that's run the variables caller arguments is going to be equal to the command that we created just like that and then finally after this is done whoops I don't know why keep doing that we don't need a comment for that and then finally after all of this what we could just say is we could just execute the command so we're gonna say using process called you know execute process which will be equal to the process starts our start info here and then all we want to say is we want to say execute process dot wait for exit and so this will just execute the process and then it automatically exit upon it being terminated okay and then finally the last method that we need for our for screen recorder application is going to be the method that stops the screen recorder so obviously we have our record video record audio and then we finally need this for when the person wants to stop so the public void stop is just going to kind of implement everything we've been doing so we obviously first thing gonna do is want to stop the watch because as you know during this entire time we've been keeping track of the time that's being recorded so we want to stop the watch first and foremost and then we're going to need to create a few variables and so this is a silver chain call int width will be equal to the bounds dot width and then we're going to say ins heights it's going to be equal to the bounds dot height here and then we're also going to create an int called frame rate which will be we're just gonna set equal to 10 at this point and then first thing we wanna do is we want to save the audio and then we want to save the video and we want to save the video with the clips save the video with the width height and frame rate here and then we want to finally oops I do not there we go oh my god why can you not get this right okay there we go so we want to then that combine the video and audio and then obviously we want to say just the video name which when was like when the first thing we define and the audio name we want to combine those two and then we want to finally delete the path of the temporary folder and we also want to delete the files except we want to target the output path and then we want to exclude the file which is will be named the output path plus / / + final name here so you want to delete all of the files except the final combined audio and video file just like that so after all of this our screen recorder class is complete and all we have to go about doing is implementing it alright so how we're going to implement this is we're just going to create you know a basic user interface which isn't really my favorite thing to do but it's kind of necessary you know users have to interact with it so we're gonna create a button which just say record I can go ahead I'll change the font size a little bit bigger so we'll say record and then we'll also say where's the text there it is stop so of one that says record one that's a stop and then we also want to allow the user to check the our change the directory so select folder here so of the users select the folder and that's actually something that is gonna be pretty important so let's just go ahead and take care of that first so what I actually like to do is I like to create a variable that's just going to be a boolean variable called folder selected which is by default is going to be set equal to false so just with this variable we're going to make sure that the user has to select a variable before they can start screen select folder before they start screen recording and so upon clicking on the button and let's also define a few more um public variables so we'll just call a string output path which will be equal to null we'll also just say string final vid name equal by default to final video dot mp4 which is what we set it equals you in here let's go ahead and save this as well so we'll do that and then upon them clicking on the change folder or select folder directory we want to create a folder browser dialog which I'll just call folder browser which will be equal to a new folder value dialog so you want to create that and then we want to say folder browser dot description going to be equal to select and output folder and then we want to say if folder browser dot show dialog is equal to a system windows forms diag not dialogue results dot okay that long piece so if they hit you know they select something then we're gonna set the output path is going to be equal to the folder browser dot selected path and then we're gonna say that the path selected or the folder selected selected is true and then so now that they've set a path what we're also going to do is we're just going to create a rectangle looks a wreck wreck tangle I don't know why I cannot spell called bounds which will be equal to our screen dot from control which make sure it's this control dot bounds and the reason we're doing that here is because we have to do this within a method and where this is we're going to where we're going to be creating a screen of origin actually we want to stern the court object to be public so we're just going to create a screen recorder called screen wreck up here which we're by default I guess we can set it equal to a new screen recorder just for purposes we'll set it equal to at first to a blank rectangle and also to this but we definitely want them to create it so we'll say down here screen rec is equal to a new screen reporter which will be the bounds as well as having the output path that was just select it and then if for whatever reason you know they don't say something then we could just do something like message box dot show please select a folder and I'm ready to split another that's an arrow so this will just make the user select a folder and so we also the next thing we want to do is we want to add a timer and this timer is probably going to be the most important time where you've ever create your life this is going to be the timer that we use to record the video and I'm going to set the interval to I believe 15 is what I found to be helpful you can play around with this interval as well as the frame rate that we created down here to try and get the audio and video to match up but this is what I found to be useful so we're going to create this timer and then I want to make sure that I'm going to name this something all this TMR record here and inside the timer what we want to do is we want to say our stream reporter dot record audio and screen recorder dot record the video so we want to make sure that we're recording both audio and video while we're in our screen recording timer here and then all the record button is going to do is gonna say TMR record dot start but actually we want to say if folder selected then duty amor don't stop and I know it's not then we just want to say message box dot show you must select an output folder before recording error this way we won't they won't crash the program by hitting record before selecting out output folder and so after this we want to go into our stop here and with stop but we just want to say we want to say screen rec dot stop we want to stop both the screen recorder and the first thing we're gonna do is I'm gonna say TMR record at dot stop you want to stop this yeah timer that's recording and then we also want to stop the screen recorder make sure that you're stopping both and not just one and then finally after all of this so we can say is we all just want to say application dot restart just because I'm too lazy to come up with a way that automatically restarts it that could be something you can work on if you really want to but and we can also create a late here that will you know keep track of the time so we can say that this is just by default equal to zero you know and we can increase the size to maybe that and then we'll just we also probably want to give this a name civil is call this lvl time and then as the screen recorder is recording we'll just say you know LBL time is equal to screen rec dots get elapsed time what Konoe dot txt there we go okay so I can get rid of this too so I believe if I am if I did all this right which I think I did this should all work so why don't we go ahead and try to run it see if we get any errors and okay it's running it's a good sign okay so the first thing that we want to do is we want to select an output folder and for this what I'm gonna do is I'm gonna select a folder that I have on my desktop which I call test folder here and I'm gonna select that as my folder and then over to see if this is working the first thing we're gonna do is I have a D Drive so let's look let's hit record and let's see what it does so if I hit record so now it should be recording and so I want to go into my I want to look for temp screen I believe is what I call the hold on well what did I call the temporary folder I call the temporary folder temp screenshot so let me see if it is crema okay so we see that the folder temporary screenshots was created and we can see all these screenshots are being added to the temporary screenshot file we have 300 of them and then so if I go ahead and I hit stop it may take a little bit but once I hit stop we should see all of the screenshots be deleted for first thing then this command will show up which will show us that it's combining the audio and video and we can actually see this happening so see all three of those videos folders are here and then looks like it's deleted all of them and I think I know why it did that just give me one second okay so I figured out why it deleted all them we actually have to go back into our screen recorder app and on the method here delete files except we have to change these to black-backed forward slashes to back slashes and then once we do that the program should run as expected so once again we have to select a folder and this is going to be at once again my test folder here and I'm just going to go into test folder I already tried it out and then I'm gonna hit record and it should be recording both my audio and video at this point so I can you know just go around and do different things and then I can hit stop and we can see that it creates the mic and video file here and then it runs the ffmpeg command in command prompt and then it combines the two into the final video and deletes both of them and if I open this up different things yeah and as you see it recorded the audio and the video and saved it into one file and it's not even I think it's about 833 kilobytes and so yeah that will pretty much do it you can once again as I said you can play around with the you know with the frame rates and the interval of this timer as well as the frame rate to try and get the audio in a video to match up a little bit more but that's pretty much all there is to creating a screen recorder and so you know I will leave all the source code I use for this down in the description as well as a link to one of my blog posts where I explain everything kind of like as I did in this video and yeah so if you liked this video go ahead and give it a thumbs up and thanks for watching see you next time bye
Info
Channel: TermSpar
Views: 40,430
Rating: undefined out of 5
Keywords: c#, screen recorder, make a screen recorder, screen recorder tutorial, c# screen recorder, create video file c#, create audio file c#, combine audio and video file c#, ffmpeg, ffmpeg tutorial, ffmpeg c# tutorial, how to use ffmpeg with c#, make a screen recorder in c#, programming, coding, computer science, advanced programming, advanced computer science, advanced coding, intermediate programming
Id: kTCmjSFodpM
Channel Id: undefined
Length: 50min 58sec (3058 seconds)
Published: Sun Dec 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.