Im looking for a easy way to record video (including audio) into a circular buffer stored in RAM.
So I can leave the video recording it will keep the feed in RAM the last 2 minutes and then have the option to commit it to memory if required.
Unfortunately, I cannot see an easy way to do this. So far I have investigated using:
MediaRecorder - I could not see a way to store the output data in a buffer. Only option is setOutputFile()
JavaCV FFmpegFrameRecorder - again the constructor for this requires passing in a file.
android.hardware.Camera.PreviewCallback - this gives a byte array for every frame which I could add to a buffer. However, this approach does not provide any audio data.
I feel like there must be a easy way to do this but so far I've not had much luck. Any help with this would be very appreciated.
JavaCV offers
cvCreateCameraCapture()
to open an interface with the camera. This code demonstrates how to capture frames from the camera and display them on a window.The interesting part resides in the
while
loop: every iteration of loop retrieves a single frame from the camera withcvQueryFrame()
. Note that the data type returned by this function isIplImage
, and this type is responsible for storing the image grabbed from the camera.All you need to do is store the
IplImage
returned bycvQueryFrame()
in your circular buffer.