我正在使用 OpenMax 来解码视频帧,我的示例是这样的:
FILE* fp = fopen("/data/local/tmp/test.yuv", "wb");
while(!isExit)
{
MediaBuffer *mVideoBuffer;
MediaSource::ReadOptions options;
status_t err = mVideoDecoder->read(&mVideoBuffer, &options);
if (err == OK)
{
if (mVideoBuffer->range_length() > 0)
{
// If video frame availabe, render it to mNativeWindow
int w = 0;
int h = 0;
int dw = 0;
int dh = 0;
int stride = 0;
sp<MetaData> metaData = mVideoBuffer->meta_data();
sp<MetaData> outFormat = mVideoDecoder->getFormat();
outFormat->findInt32(kKeyWidth , &w);
outFormat->findInt32(kKeyHeight, &h);
int64_t timeUs = 0;
metaData->findInt64(kKeyTime, &timeUs);
metaData->findInt32(kKeyDisplayHeight, &dh);
metaData->findInt32(kKeyDisplayWidth, &dw);
metaData->findInt32(kKeyStride, &stride);
printf("out format w:%d h:%d dw:%d dh:%d stride:%d timestamp:%lld\n",
w, h, dw, dh, stride, timeUs);
if(fp)
{
printf("decode a frame, range_length = %d range_offset = %d size = %d width = %d height = %d\n",
mVideoBuffer->range_length(), mVideoBuffer->range_offset(), mVideoBuffer->size(), w, h);
fwrite(mVideoBuffer->data( ) + mVideoBuffer->range_offset( ), 1, mVideoBuffer->range_length(), fp);
}
metaData->setInt32(kKeyRendered, 1);
}
mVideoBuffer->release();
}
else
{
printf("end of file\n");
isExit = true;
}
}
fclose(fp);
输出是这样的:
out format w:1280 h:720 dw:0 dh:0 stride:0 timestamp:44044
decode a frame, range_length = 1417216 range_offset = 0 size = 1417216 width = 1280 height = 720
我的问题是如何知道 MediaBuffer 存储的 yuv 实际大小,因为 1280 x 736(我猜步幅是 32)x 1.5 = 1413120,但是 mVideoBuffer 的 range_length() 是 1417216,没有常规我可以得到 yuv 大小,请帮帮我,谢谢!