首页 > 解决方案 > 如何以 60fps 制作离线 png 序列记录器?

问题描述

我想以非实时(离线)的方式捕获 Unity 相机的 60fps、4k 图像序列。

到目前为止,我能够成功捕获每一帧,但我无法弄清楚如何使其离线并符合 60fps。

我正在捕捉这样的帧:

            // get main camera and manually render scene into rt
            Camera camera = this.GetComponent<Camera>(); // NOTE: added because there was no reference to camera in original script; must add this script to Camera
            camera.targetTexture = renderTexture;
            camera.Render();
            this.lastRenderTime = Time.realtimeSinceStartup;

            // read pixels will read from the currently active render texture so make our offscreen 
            // render texture active and then read the pixels
            RenderTexture.active = renderTexture;
            screenShot.ReadPixels(rect, 0, 0);

            // reset active camera texture and render texture
            camera.targetTexture = null;
            RenderTexture.active = null;

            // get our unique filename
            string filename = uniqueFilename((int)rect.width, (int)rect.height);

            // pull in our file header/data bytes for the specified image format (has to be done from main thread)
            byte[] fileHeader = null;
            byte[] fileData = null;

 // create new thread to save the image to file (only operation that can be done in background)
            new System.Threading.Thread(() =>
            {
                // create file and write optional header with image bytes
                var f = System.IO.File.Create(filename);
                if (fileHeader != null) f.Write(fileHeader, 0, fileHeader.Length);
                f.Write(fileData, 0, fileData.Length);
                f.Close();
                Debug.Log(string.Format("Wrote screenshot {0} of size {1}", filename, fileData.Length));
            }).Start();

有人可以指出我正确的方向吗?

标签: c#unity3d

解决方案


时间设置中,将所有时间步长设置为 1/60(约 0.01666667)

然后在 OnPostRender 事件中捕获屏幕。

时间设置


推荐阅读