问题描述
我的有关$ P $工作的 Android的测试案例中的一个的实现pviewTexture记录与新媒体codeC和MediaMuxer API的Android 4.3的。
I am working on an implementation of one of the Android Test Cases regarding previewTexture recording with the new MediaCodec and MediaMuxer API's of Android 4.3.
我已经成功了recordingHint设置相机paremeters记录约30fps的帧率的preVIEW流。
I've managed to record the preview stream with a framerate of about 30fps by setting the recordingHint to the camera paremeters.
不过,我遇到了一个延迟/滞后的问题,真的不知道该如何解决这个问题。当使用非常标准质量设置(1280×720,〜8.000.000的比特率)的preVIEW和EN codeD材料中记录的相机preVIEW患有偶尔滞后。更具体地:该滞后发生大约每2-3秒和大约300-600ms
However, I ran into a delay/lag problem and don't really know how to fix that. When recording the camera preview with quite standard quality settings (1280x720, bitrate of ~8.000.000) the preview and the encoded material suffers from occasional lags. To be more specific: This lag occurs about every 2-3 seconds and takes about 300-600ms.
通过跟踪延迟我能计算出延迟来自于code以下行中的drainEn codeR的方法:
By tracing the delay I was able to figure out the delay comes from the following line of code in the "drainEncoder" method:
mMuxer.writeSampleData(mTrackIndex, encodedData, mBufferInfo);
此行是在循环中调用如果EN codeR具有可用于混流数据。目前,我被MediaMuxer转换为MP4格式不记录音频所以才有了H264流。
This line is called in a loop if the encoder has data available for muxing. Currently I don't record audio so only the h264 streams is converted to a mp4 format by the MediaMuxer.
我不知道这是否有事情做与延迟,但它总是发生在循环需要两个迭代出列的EN codeR的全部信息(以更加具体的,它总是发生在这两个迭代的第一)。在大多数情况下,一次迭代就足以出列的EN codeR。
I don't know if this has something to do with that delay, but it always occurs when the loop needs two iterations to dequeue all available data of the encoder (to be even more specific it occurs always in the first of these two iterations). In most cases one iteration is enough to dequeue the encoder.
由于没有太多的信息在网上对这些新的API的任何帮助非常AP preciated!
Since there is not much information online about these new API's any help is very appreciated!
推荐答案
我怀疑你要咬伤的 MediaMuxer
磁盘写入。可以肯定的最好的办法就是录制过程中运行systrace,看到在暂停期间发生了什么实际发生的事情。 (systrace 文档,的, bigflake例如 - 截至目前只有后者是Android 4.3)更新
I suspect you're getting bitten by the MediaMuxer
disk write. The best way to be sure is to run systrace during recording and see what's actually happening during the pause. (systrace docs, explanation, bigflake example -- as of right now only the latter is updated for Android 4.3)
如果是那样的话,你可以通过一个单独的线程运行 MediaMuxer
例如,通过一个同步的H.264数据反馈给它缓解这个问题队列中。
If that's the case, you may be able to mitigate the problem by running the MediaMuxer
instance on a separate thread, feeding the H.264 data to it through a synchronized queue.
做这些暂停定期发生,每5秒?该CameraToMpegTest示例配置EN codeR输出I帧每5秒(与30fps的的预期帧速率),这将导致一个全尺寸的帧是输出,而不是微小的增量。
Do these pauses happen regularly, every 5 seconds? The CameraToMpegTest example configures the encoder to output an I-frame every 5 seconds (with an expected frame rate of 30fps), which results in a full-sized frame being output rather than tiny deltas.
这篇关于木星相机preVIEW H264连接codeD元素流MediaMuxer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!