IBG
IBG

Reputation: 465

Is it possible to use a circular buffer for video frames on iOS?

I'm currently looking for a way to create a "live photos"-like functionality in iOS, but using videos. The goal is to have the application store a few seconds of frames prior to starting taking a video. I'm thinking a circular buffer would serve well here, but most of the libraries I've seen are for audio only. Given that the live photos functionality is exclusive to iPhone 6S, I'm wondering if a functionality like this is possible on a device with equal amount of RAM, for example an iPad Air 2, or a device with lesser RAM, for example iPhone 6.

Upvotes: 1

Views: 1417

Answers (2)

werediver
werediver

Reputation: 4757

A long time ago I was working on a car DVR / dashcam app for iOS. It was necessary to save up to thirty minutes of the recent video and it was obviously impossible to store in RAM.

The task was solved by writing the video to a file up to the required length, then writing to the second file, then again switching to the first one (overwrite) and so on. With such process I was able to cut & glue the latest thirty minutes from these two files at any moment of time.

As I remember there was no problems with performance.

Maybe this approach will be useful to you.

Upvotes: 2

MoDJ
MoDJ

Reputation: 4425

In theory, it would be possible to store and loop video, but in practice you will find that it is unlikely to actually work for full screen video at a fast FPS rate like 30 FPS. The problem is total amount of memory used for video. Each pixel is 32 bits of data (RGBX) each pixel is basically a word and you need to multiply by W x H to figure out how large that is for the given camera resolution. To make a long story short, for a very large W and H there is too much data for the CPU and memory bus to keep up with reads and writes. Now iOS devices do have hardware to help with this task, for example you can encode movies using the built in hardware, but that is likely to be the only way you will be able to get it working when dealing with very large W x H values and fast frame rates. You also have to be careful with aspect ratios because you camera will likely capture pictures in aspect ratios that the h.264 encoding hardware will not support.

Upvotes: 1

Related Questions