Unity UWP how to record a game screen in a game? (Windows)

First of all, I am sorry about my English.
I hear to this community is very powerful!
I’m in trouble now.
How to record a game screen in a game? in a window environment.
I have tried many ways. but it didn’t run when it was built with UWP. All of asset store and common method.
So I try to save pictures as a function of screencapture and convert them into video. with ffmpeg.
But this is also too hard for me to relate to Unity.
If you know how to record a video or How to use ffmpeg in Unity or another things.
comment please! any method.

I’m assuming youre doing something like this to get screenshots : Unity - Scripting API: Time.captureFramerate

If you want to automate the ffmpeg cmd part in the application, you can run cmd commands from code like this:

Run ffmpeg commands after you have captured all the screenshots.
Also check: command line - Adding frame to video with same FPS using FFMPEG concat reduces output FPS - Super User

Bear in mind that capturing screenshots is a very taxing process. Not to mention the storage it take up to store all the sceenshots for post processing.
If you are not targeting real time then this is a great solution.

If you want to do this real time and need it to be really fast, an other way to do this is using native plugins. Headsup, this is optimal but a LOT of work.

Here is a general overview of what you’d do:

  1. Get the camera view into a Texture2D. (Unity - Scripting API: RenderTexture.active)

  2. Send the texture to a native plugin. (Very good place to start : https://bitbucket.org/Unity-Technologies/graphicsdemos/src/0615fcd65c97/NativeRenderingPlugin/UnityProject/Assets/Plugins/?at=default)

  3. Download and set ffmpeg include and library directories in your native plugin project. (https://ffmpeg.zeranoe.com/builds/ – I usually use dev)

  4. Now, the hardest part is to get the RGB data from unity texture thats been sent to the native plugin. (graphics-driver-samples/render-only-sample/rostest/util.cpp at 7696d8388d9d94f2190c8405f1f7a8335924722d · microsoft/graphics-driver-samples · GitHub)

NOTE: This will also depend on Grapchic API that your machine is using. Windows usually uses Direct3D api. If using OpenGL see glGetTexImage.

  1. Once you have the RGB data, you can do something like this: video - C++ FFmpeg create mp4 file - Stack Overflow to generate a video from it.

This maybe an overkill, but hope this helps someone!

P.S: I’ve only done parts of this solution myself so this is a hunch.