我尝试将原始h264视频渲染到曲面(解码后)并将其同时写入文件。 渲染工作正常,但是当我想获得当前输出缓冲区时,它的大小总是为8,输出文件的大小为3,87 Ko。
输出缓冲区似乎被表面锁定(ANativeWindow)? 任何人都可以给我一个建议,而无需创建另一个编解码器吗?
编解码器配置有输出表面:
if (AMEDIA_OK == AMediaCodec_configure(d->codec, d->format, d->window /*the native window */, NULL, 0)
当我尝试获取输出缓冲区时,这是代码snipet:
if (!d->sawOutputEOS) {
AMediaCodecBufferInfo info;
auto status = AMediaCodec_dequeueOutputBuffer(d->codec, &info, -1);
if (status >= 0) {
if (info.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) {
LOGV("output EOS");
d->sawOutputEOS = true;
d->isPlaying = false;
}
int64_t delay = 333000;
usleep((useconds_t )delay / 15);
size_t size;
// here i get the output buffer
uint8_t *outputbuffer = AMediaCodec_getOutputBuffer(d->codec,status,&size);
write(d->fd1,outputbuffer,size); // the output is always 0
LOGV("%d",size); // the size is always 8
LOGV("FRAME num : %d", counter[d->nb]++);
AMediaCodec_releaseOutputBuffer(d->codec, status, info.size != 0);
if (d->renderonce) {
d->renderonce = false;
return;
}
} else if (status == AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
LOGV("output buffers changed");
} else if (status == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED) {
auto format = AMediaCodec_getOutputFormat(d->codec);
LOGV("format changed to: %s", AMediaFormat_toString(format));
AMediaFormat_delete(format);
d->formatChanged = true;
} else if (status == AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
LOGV("no output buffer right now");
} else {
LOGV("unexpected info code: %zd", status);
}
}
提前致谢
答案 0 :(得分:2)
没有锁定;您要求解码器工作以进行显示,因此它使用最快的路径进行显示,而不会将像素暴露给可读存储器。您可能会发现格式为不透明的COLOR_FormatSurface,如here所述。