Record Video To Byte Array Without Writing To File

天涯浪子 提交于 2019-12-07 11:04:18

问题


I'm implementing a custom video camera using the Google Developer API Guide; it uses the MediaRecorder class to create and manage all the settings/operations of the video camera.

Save for the fact that it's taking way too long to write the file to the phone (after recording, it'll be about 5 minutes before I even get to see the file under Gallery), it's working as it should.

But I don't want a file: I need the raw byte array the recording produces, before it's dumped into a file.

Does MediaRecorder even allow you to do this? Am I in the right direction?

A good example of what I need is how the PictureCallback's onPictureTaken() method gives you a byte array which contains the picture in bytes.


回答1:


MediaRecorder is intended to be simple: tell it where the inputs come from, give it a file to write to, and let it run.

If you want something more flexible, you need to use MediaCodec. The set of features you want doesn't really exist until API 18 (Android 4.3).

Grafika includes the "Continuous capture" activity, which records H.264 video to a circular buffer in memory, and writes the current set of frames to a file when you hit "Capture". This is video-only; if you want audio, you'd need to deal with that separately.

For earlier versions of Android you'd need to use a 3rd-party library like ffmpeg to handle the video encoding, which will reduce your frame rate significantly.




回答2:


after recording, it'll be about 5 minutes before I even get to see the file under Gallery

That's probably because you didn't do anything to make it show up in the Gallery faster, such as use MediaScannerConnection and scanFile(). The Gallery doesn't find out files until either you tell it about the file or it comes up in a periodic scan.



来源:https://stackoverflow.com/questions/22965817/record-video-to-byte-array-without-writing-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!