问题
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.
回答1:
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 with cvQueryFrame()
. Note that the data type returned by this function is IplImage
, and this type is responsible for storing the image grabbed from the camera.
All you need to do is store the IplImage
returned by cvQueryFrame()
in your circular buffer.
来源:https://stackoverflow.com/questions/20277255/android-record-video-into-a-circular-buffer-and-storing-it-in-ram