Home > Mobile >  How OBS record hidden window?
How OBS record hidden window?

Time:11-12

I'm making a program to record a window that is obscured by another window via python and WIN32API library.

Through many searches, I succeeded in capturing the hidden window through hwnd and BitBlt, but the execution time of my code is not stable.

I tried to provide the recording function by selecting 30~60 fps, but the time required to capture the hidden window and write() it to the video object of cv2 is irregular, so I can't make a 60fps video.

So I thought of OBS and Discord. In the case of OBS, it is possible to enforce stable recording for obscured windows. For Discord, there is a feature that allows you to select a specific window and share it with multiple people in real time (this can also be done for hidden windows).

I'd like to know how these programs provide stable video for occluded windows. I'm a student, and I'm not elite. I am asking this question because it is difficult to analyze the vast Github source code of OBS. Can someone give me an explanation of how the above program captures the screen?

CodePudding user response:

@dy.kim, don't be afraid of large codebases. screencap of OBS

CodePudding user response:

Last time I checked, OBS was doing it with low-level hacks instead of APIs.

Specifically, they have wrote a DLL which they inject into the target application using CreateRemoteThread WinAPI. Then, they patch application’s code to intercept calls to IDXGISwapChain.Present method. Once a call is intercepted, the injected code has access to D3D frame buffer texture. It can copy that texture into another texture on GPU, and then do something with the copy. One possibility is DXGI surface sharing to pass the copy from the target application into the capturing process. The APIs for that don’t require both sides of the sharing to be in the same process, textures can be shared across processes just fine.

Unfortunately for you, their approach is borderline impossible to re-implement in higher-level languages like Python. Such things are only doable in C or similar low-level languages, and relatively hard to implement and debug.

  • Related