• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by int_32 · Jan 18 at 06:15 PM · screenshotscreencapture

ScreenCapture.CaptureScreenshot skips frames

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KISP · Jan 18 at 09:23 PM

FixedUpdate doesn't usually run once a frame as it's based on the timestep of the physics engine. Try Update instead.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image int_32 · Jan 19 at 12:08 AM 0
Share

I know, but it runs every fixed amount of time. Update runs at "random" time since last update, so it can't provide fixed frame rate.

avatar image KISP int_32 · Jan 21 at 02:38 PM 0
Share

You can't have it both ways. Fps can change over time, so if you want to take a picture every x frames, there's no way to guarantee it's happening every x seconds. Likewise, if you take a picture every x seconds, an arbitrary amount of frames occur in-between.

avatar image int_32 KISP · Jan 21 at 02:40 PM 0
Share

Currently I'm going to use this solution: get every frame and save it every fixed amount of time, even if it was not updated.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Screenshot resolution using ScreenCapture 1 Answer

capture a screen shot and show in the album folder 1 Answer

Take screenshot and use it as texture using ScreenCapture 1 Answer

How to do screenshot and save it in phone as png(not texture)? 0 Answers

Failed to store screenshot in build 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges