In my iOS app, I am using NSTime to invoke a method which takes screenshot of the device screen. I am taking 30 screenshots per second. On simulator its working fine (as the processor of Mac is far more powerful than iPad). But it takes less number of screenshots in actual device. How can I do this? Any reliable alternative for timer? Please help
Asked
Active
Viewed 605 times
0
-
1how about recording a video and grab the image from it ? I misread it is from camera – Raptor Jun 07 '13 at 10:54
-
1Not possible - find a different solution... e.g. slow-down whatever happens within your app to adapt to the achieveable screenshot rate. – Till Jun 07 '13 at 10:54
-
1@ShivanRaptor recording a video of what? Would you be able to record the screen without taking screenshots?.... – Till Jun 07 '13 at 10:55
-
It's not really the processor causing the lag - it's writing to the flash problem... – Rok Jarc Jun 07 '13 at 10:58
-
oops. I misread. It's not possible. you can't take screenshot that fast. Tricky way: Facing a mirror, take front camera video, grab the screenshot from it – Raptor Jun 07 '13 at 10:58
-
I think its happening due to unreliability of NSTimer which is highlighted [here](http://stackoverflow.com/questions/915410/nstimer-on-device-is-slower-than-in-simulator). But I couldn't find a proper alternative to fulfill my purpose. Can somebody help? – Yogi Jun 07 '13 at 11:01
-
@Till: Thanks Till. Isn't there any other way than NSTimer to achieve this thing? Can you please explain a bit more? – Yogi Jun 07 '13 at 11:05
-
Are you saving the screenshots to disk or just holding them in an array to be processed later? The latter would be much more efficient. – Mark McCorkle Jun 07 '13 at 11:10
-
@DCGoD:I am saving them in Documents folder of my application. If I use array then it will lead to creation of a very large array which may cause memory issues. – Yogi Jun 07 '13 at 11:12
-
You said 30 screenshots in a second. Are you wanting to achieve more than this? If not, save all 30, write to disk in a different thread. But yes, inevitably you are bound by the writing speeds of the device so using ram to store this quickly may be the only option. Or lower the quality of the captures. – Mark McCorkle Jun 07 '13 at 11:17
-
@DCGoD: I am trying to take 30 screenshots in a second but it takes less number of screenshots in device while works fine on simulator. Sorry for not being clear. – Yogi Jun 07 '13 at 11:25
-
Probably not possible at 30fps but I would suggest you to pack your operation into an NSOperation and pass them to an NSOperationQueue. If you don't income into memory issues you can have pretty good results. – Andrea Jun 07 '13 at 12:58
-
@Andrea: Thanks Andrea. But will this be an effective way? Because NSOperationQueue is used to complete the task in batches while the screenshots should be taken serially as I want to create video from these screenshots. – Yogi Jun 07 '13 at 13:31
-
@Yogi I still didn't understand if you want to take screens from camera or from the device, but if you can wait that the device elaborate the images, NSOperationQueue is fine, you can attach a timestamp if you want to build a movie or use a serial queue with GDC, of course you need to keep a reference of the "source" image for each frame and dispose it at the end of the process. I image something like that: Take the screen->put it in NSOperation that do whatever you like and save image on disk->add to queue. – Andrea Jun 07 '13 at 15:27
-
@Andrea: Actually what I am trying to do is take the screenshots at some specified rate when the app is running and use these screenshots to create a video with same FPS. So I am taking screenshots programmatically and not using camera. Hope this makes sense now. – Yogi Jun 11 '13 at 05:42
-
@yogi did you find a solution? – STerrier Aug 24 '21 at 09:49
-
@STerrier I think I went on with NSTimer only. Long time since then. Now you can get better solutions which can actually capture a video of your screen like [here](https://medium.com/flawless-app-stories/wyler-screen-recording-made-easy-on-ios-b6451511a715). – Yogi Aug 25 '21 at 05:13