如何制作60fps的离线png序列记录器?

时间:2019-03-10 05:53:43

标签: c# unity3d

我想以非实时方式(离线)捕获Unity Camera的一系列图像(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();

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

1 个答案:

答案 0 :(得分:1)

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

然后在OnPostRender事件中单击caputre屏幕。

timesettngs