我试图流数据(h.264原始1080p)到android并呈现它到表面view.The问题是,如果我发送数据速度超过45fps解码器输出像素化(输入索引&输出索引是-1或没有准备好)Mediacodec渲染到表面缓慢
此外,如果我发送720p或更低分辨率的视频结果是相同的我无法呈现(没有像素化)比45fps更快。
但如果我设置渲染标志为“假”,在releaseOutputBuffer(),我能够达到75fps(我接收输入&输出指标均正常)
那么,有没有“解锁”的一种方式帧率?或另一种渲染速度更快的方式。
注意:我在ndk里面做这个。
初始化解码器()
AMediaFormat *AVm_format = AMediaFormat_new();
AMediaFormat *AVm_formattesting = AMediaFormat_new();
AVm_codec = AMediaCodec_createDecoderByType("video/avc");
AVm_formattesting =AMediaCodec_getOutputFormat(AVm_codec);
int formatint=0;
AMediaCodec_createCodecByName("OMX.qcom.video.decoder.avc");
AMediaFormat_setString(AVm_format,AMEDIAFORMAT_KEY_MIME,"video/avc");
AMediaFormat_setInt32(AVm_format,AMEDIAFORMAT_KEY_HEIGHT,1920);
AMediaFormat_setInt32(AVm_format,AMEDIAFORMAT_KEY_WIDTH,1080);
AMediaFormat_setInt32(AVm_format,AMEDIAFORMAT_KEY_COLOR_FORMAT,13);
try {
AMediaCodec_configure(AVm_codec, AVm_format, Nwindow, NULL, 0);
LOGD("Configure finished...\n");
AMediaCodec_start(AVm_codec);
LOGD("Decoder started\n");
}catch(std::exception e){
LOGD("FAILED TO CONFIGURE DECODER\n");
}
解码(...)
//pData is the frame I recive
//sz is the size of the frame
ssize_t indx = AMediaCodec_dequeueInputBuffer(AVm_codec, 0);
if (indx >= 0) {
input = AMediaCodec_getInputBuffer(AVm_codec, indx, &insize);
// memset(input,0,sz);
memcpy(input,pData,sz);
AMediaCodec_queueInputBuffer(AVm_codec, indx, 0, sz, 0, 0);
}
ssize_t indy = AMediaCodec_dequeueOutputBuffer(AVm_codec, AVm_buffinfo, 0);
if (indy >= 0) {
AMediaCodec_releaseOutputBuffer(AVm_codec, indy, false);
} else if(indy == AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED){
LOGD("output buffers changed\n");
} else if (indy == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED) {
AMediaFormat *format = NULL;
format = AMediaCodec_getOutputFormat(AVm_codec);
LOGD("format changed to: %s", AMediaFormat_toString(format));
AMediaFormat_delete(format);
LOGD("format changed to:\n");
} else if (indy == AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
LOGD("no output buffer right now\n");
} else {
LOGD("unexpected info code: %zd\n", indy);
}
如果需要其他任何东西让我知道吧。
感谢您的回复。基本上,流正在渲染(无论artifact0为45fps,无论解析度是什么分辨率,我只是想知道如果表面视图有一个Vsync限制fps。 – MyNameisAwesome
SurfaceView将限制您的设备刷新率。仅仅作为'releaseOutputBuffer()'在等待vsync时花费很长时间才会返回 - 它不应该对输出的质量产生任何影响。我的猜测是时序变化暴露了代码中的竞争条件。如果你需要将帧解码得比它能够显示的速度快,你需要将“false”传递给释放方法来丢弃帧(例如替代真/假以将显示的帧速率减半)。 – fadden