I need to get series of screenshots with constant frame rate to create video from it with FFMPEG.
I use ScreenCapture.CaptureScreenshot()
method to capture screenshots in every FixedUpdate()
:
void FixedUpdate()
{
var delta = Time.deltaTime;
if (Time.realtimeSinceStartup <= 180f)
{
CaptureScreenshot();
}
else
{
Debug.Log("Got " + currentFrame + " screenshots");
}
}
private void CaptureScreenshot()
{
var fileName = currentFrame++.ToString("000000000") + ".png";
var filePath = "/tmp/frames/" + fileName;
ScreenCapture.CaptureScreenshot(filePath);
}
But as I can see, it skips lots of screenshots:
$ ls -lah . | head
-rw-r--r-- 1 user wheel 139K Jan 18 21:05 000000001.png
-rw-r--r-- 1 user wheel 139K Jan 18 21:05 000000006.png
-rw-r--r-- 1 user wheel 139K Jan 18 21:05 000000009.png
-rw-r--r-- 1 user wheel 139K Jan 18 21:05 000000013.png
-rw-r--r-- 1 user wheel 139K Jan 18 21:05 000000016.png
-rw-r--r-- 1 user wheel 139K Jan 18 21:05 000000019.png
Note: I use FixedUpdate()
because I need constant frame rate. Some performance issues are OK, it’s 2D scene that is not so complex.
So, what should I do to capture “screen” contents on every call or get constant frame rate?