【发布时间】:2016-10-18 03:51:59
【问题描述】:
我想通过将颜色格式设置为COLOR_FormatYUV420Flexible 来使用 MediaCodec 进行编码。
我的输入缓冲区是 yuv420p。当我像这样输入缓冲区时:
int inputBufferIndex = mEncoder.dequeueInputBuffer(-1);
mCurrentBufferIndex = inputBufferIndex;
if (inputBufferIndex >= 0) {
ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
//if(VERBOSE)
Log.i(TAG,"pos:"+inputBuffer.position()+"\tlimit:"+inputBuffer.limit());
inputBuffer.clear();
return inputBuffer;
}
但有些设备的颜色不对。 所以我试试这个:
int inputBufferIndex = mEncoder.dequeueInputBuffer(-1);
mCurrentBufferIndex = inputBufferIndex;
if (inputBufferIndex >= 0) {
Image img = mEncoder.getInputImage(inputBufferIndex);
if(img==null)
return null;
//mCurrentInputPlanes = img.getPlanes();
ByteBuffer buffers[]={img.getPlanes()[0].getBuffer(),
img.getPlanes()[1].getBuffer(),
img.getPlanes()[2].getBuffer()};
我将缓冲区填充到 YUV 通道。它适用于某些设备。但是moto X pro和huawei P7在调用getInputImage时会得到null。
文档说图像不包含原始数据。
但它也提到自 API 21 起支持COLOR_FormatYUV420Flexible。那么我应该如何解决这个问题。
【问题讨论】:
-
我在很多 Galaxy Note3 和 Galaxy Tab 4 10.1 设备上都遇到了这个问题,还有其他人提供的信息吗?
-
@FTLRalph 你能发布完整的代码示例吗?从问题中不清楚如何将 YUV 数据复制到输入缓冲区。另外,您能否发布显示问题的编码视频示例?对我来说,错误的颜色听起来像是步幅或填充问题,但需要更多信息才能调试。
-
您检查是否支持 COLOR_FormatYUV420Flexible?根据此链接:stackoverflow.com/questions/30857610/…
标签: android encode android-mediacodec