Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recording video of only one Window

I need to capture my screen as a video, for that I used Expression Encoder 4, but in my application I also need to capture one single window, but I can't find a way of doing it, with EE4 I tried changing dynamically the CaptureRectangle of my ScreenCaptureJob, but that doesn't seem to be possible. So my question is, do you know anyway of doing this 'single window capture' using preferably C# or maybe C++?

like image 755
V.M. Avatar asked Nov 03 '22 12:11

V.M.


1 Answers

You could get the window handle of the window that you're interested in, set a timer, and at each timer tick capture that window's contents. Doing so is non-trivial, but certainly possible. I did it in C many years ago, but that code is long gone.

The problem is simpler if you just want to capture a rectangular area of the screen. You can get the window handle, query its size and position, and then copy that area from the screen. In C or C++, you would get the desktop DC and copy bits from it. In C#, you could create a Bitmap that's the size of the window, call Graphics.FromImage to get a Graphics object for the image, and then call CopyFromScreen to get the window contents. The drawback is that this only works if nothing is covering the window in question. If something is covering any part of the window, you're going to capture that.

In any case, you end up with a stream of images that you need to combine into a video. There are a number of libraries that will do that. For a C# solution, you might start by looking at create video from streamed images c#. I suspect there are similar libraries for C++. There are also some command line tools that will do it, although my experience with them has been less than satisfactory.

like image 54
Jim Mischel Avatar answered Nov 15 '22 16:11

Jim Mischel