将视频录制到Android上的循环缓冲区 [英] Video recording to a circular buffer on Android

查看:119
本文介绍了将视频录制到Android上的循环缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找最好的方法(如果有的话)将连续视频捕获到SD卡上的循环缓冲区中,从而允许用户在事件发生后捕获事件.

标准视频录制API允许您直接直接写入文件,并且当达到限制(由用户设置或SD卡的容量)时,必须停止并重新开始录制.这将创建长达2秒的长时间窗口,在该窗口中不会运行录制.这是某些现有应用(例如DailyRoads Voyager)已经完成的工作.为了最大程度地减少错过重要事件的机会,您可以将拆分时间设置为较长的​​时间(例如10分钟),但是如果在此时间间隔即将结束时发生事件,那么您会在开始时存储9分钟的空闲时间,从而浪费了空间.>

因此,我现在的想法如下:我将有一个大文件用作缓冲区.我将使用一些发现的代码来捕获帧并将它们自己保存到文件中,并在最后四处回绕.当用户想要保留某些部分时,我将通过指向缓冲区起点和终点的指针对其进行标记.记录可以像以前一样继续,跳过标记为保留的区域.

停止录制后,或者在后台线程录制期间(取决于电话/卡速度),我将标记的区域复制到另一个文件中,并删除覆盖保护.

主要问题,如果您不关心上面的详细信息:我似乎找不到在Android SDK中将单个帧转换为视频文件的方法.可能吗?如果不是,是否有可用的库(也许以本机代码形式)可以做到这一点?

我不太在乎未压缩帧的大缓冲区,但是导出的视频应以Android友好的格式压缩.但是,如果有一种压缩缓冲区的方法,我想听听.

谢谢.

解决方案

在Android的 MediaRecorder 中,有两种方法可以指定输出.一个是文件名,另一个是 FileDescriptor .

使用 ParcelFileDescriptor 的静态方法 fromSocket ,您可以创建指向套接字的 ParcelFileDescriptor 的实例.然后,调用 getFileDescriptor 来获取 FileDescriptor ,以将其传递给 MediaRecorder .

由于您可以从套接字获取编码的视频(就像创建本地Web服务器一样),因此您将能够访问视频的各个帧(尽管不是直接访问),因为您需要先对其进行解码

I'm looking for the best way (if any...) to capture continuous video to a circular buffer on the SD card, allowing the user to capture events after they have happened.

The standard video recording API allows you to just write directly to a file, and when you reach the limit (set by the user, or the capacity of the SD card) you have to stop and restart the recording. This creates up to a 2 second long window where the recording is not running. This is what some existing apps like DailyRoads Voyager already do. To minimize the chance of missing something important you can set the splitting time to something long, like 10 minutes, but if an event occurs near the end of this timespan you are wasting space by storing the 9 minutes of nothing at the beginning.

So, my idea for now is as follows: I'll have a large file that will serve as the buffer. I'll use some code I've found to capture the frames and save them to the file myself, wrapping around at the end. When the user wants to keep some part, I'll mark it by pointers to the beginning and end in the buffer. The recording can continue as before, skipping over regions that are marked for retention.

After the recording is stopped, or maybe during that on a background thread (depending on phone/card speed) I'll copy out the marked region to another file and remove the overwrite protection.

Main question, if you don't care about the details above: I can't seem to find a way to convert the individual frames to a video file in the Android SDK. Is it possible? If not, are there any available libraries, maybe in native code, that can do this?

I don't really care about the big buffer of uncompressed frames, but the exported videos should be compressed in an Android-friendly format. But if there is a way to compress the buffer I would like to hear about it.

Thank you.

解决方案

In Android's MediaRecorder there is two way to specify the output. One is a filename and another is a FileDescriptor.

Using static method fromSocket of ParcelFileDescriptor you can create an instance of ParcelFileDescriptor pointing to a socket. Then, call getFileDescriptor to get the FileDescriptor to be passed to the MediaRecorder.

Since you can get the encoded video from the socket (as if you were creating a local web server), you will be able to access individual frames of the video, although not so directly, because you will need to decode it first.

这篇关于将视频录制到Android上的循环缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆