Z
Z
zhogar2016-08-23 16:46:24
Android
zhogar, 2016-08-23 16:46:24

How to implement a circular video stream buffer?

Hello.
It is necessary to implement a circular buffer of the video stream coming from the camera of a mobile device running Android 4.4. The fact is that the standard MediaRecorder has a fixed VideoDuration, upon reaching which an event is called to save the video file. But for my tasks, it is absolutely not suitable.
Tell me which way to go in order to implement a "continuous" (cyclic) frame buffer of a video stream with a given FPS=25fps. And unload data only on a certain event.
Approximate buffer implementation block diagram:
0d10ab5b33364b819ffdac5a4ce2bed7.png
Let's assume that our buffer implements FPS = 25fps, the duration (required size) of the video file at the output VideoDuration = 15s, and we get that we need a buffer at FPS * VideoDuration = 375 frames.
For example, with a video resolution of 1024 x 786 pixels, and a pixel color depth of, say, 4 bits, the size of one frame is FrameSize = H * W * bit = 3219456 bits, and then this still needs to be multiplied by the number of stored frames 375, as a result, the size of such a buffer it comes out equal to (3219456 * 375) / 8 / 1024 / 1024 it turns out about 143 MB, agree to keep such a volume, and even more so, work with it, in memory or a file, it is very difficult.
Therefore, it is also necessary to implement algorithms for compressing frames and, accordingly, decompressing when unloading from the buffer to a file.
Let it not be a MediaRecorder in the full sense, but a class that implements only recording frames into a buffer with their subsequent unloading without sound.
In one of his personal correspondence on the current issue, with a competent specialist, he advised the following:
1) Either work directly with the camera, but then there will be a more hardware-dependent application. For me, this option is not suitable. 2) Or write your own video codec. But here for me it’s generally a dark forest.
What do you say and advise? Who has had similar issues?
The fact is that it turned out to be very difficult for me to implement this buffer, which is why I actually turn to you for help.
Thank you. Sincerely.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tsimur_S, 2016-08-23
@zhogar

https://github.com/google/grafika/blob/master/src/... может этот гугловский пример вам подойдет?

Z
zhogar, 2016-08-23
@zhogar Автор вопроса

Я могбы использовать

public void onPreviewFrame(byte[] data, Camera camera) { ... }
, но по моему это бредовая идея...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question