Delay in preparing media recorder on android

大憨熊 提交于 2019-12-03 22:16:01

So Instagram also suffers from the MediaRecorder delay. You can tell when you do quick taps. The progress bar resets. It's only once you've held the record button for longer than a second does it actually capture anything.

This is just an inherent flaw in MediaRecorder. The only way around this is to use the setPreviewCallbackWithBuffer API. In using this API you provide the camera with buffers to display the preview, and it calls back to you with the YUV frame that it showed on the preview surface. You can then pass this buffer through to MediaCodec to encode the video.

Ideally, OEMs have implemented MediaCodec to understand the buffers being passed from the camera, but we've seen spotty performance on a lot of devices pre 4.3. Random MediaCodec implementations that expect different alignments and YUV formats than the camera provides for example. You'll also have to capture audio yourself and maintain AV sync.

Alternatively you can pass the buffers to ffmpeg to encode - just be careful which codecs you build into ffmpeg. VP8 + vorbis is the best performing royalty free codecs we've seen.

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