问题
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