Getting QualComm encoders to work via MediaCodec API

会有一股神秘感。 提交于 2019-12-18 11:43:13

问题


I am trying to do hardware encoding (avc) of NV12 stream using Android MediaCodec API.

When using OMX.qcom.video.encoder.avc, resolutions 1280x720 and 640x480 work fine, while the others (i.e. 640x360, 320x240, 800x480) produce output where chroma component seems shifted (please see snapshot).

I have double-checked that the input image is correct by saving it to a jpeg file. This problem only occurs on QualComm devices (i.e. Samsung Galaxy S4).

Anyone has this working properly? Any additional setup / quirks necessary?


回答1:


Decoder(MediaCodec) has its MediaFormat, it can be received using getOutputFormat. Returned instance can be printed to log. And there you can see some useful information. For example in your case value like "slice-height" could be useful. I suspect that it is equal to height for 1280x720 and 640x480 and differs for other resolutions. Probably you should use this value to get chroma offset.




回答2:


Yep, the OMX.qcom.video.encoder.avc does that but not on all devices/android version. On my Nexus 4 with Android 4.3 the encoder works fine, but not on my S3 (running 4.1)

The solution for an S3 running 4.1 with the OMX.qcom.video.encoder.avc (it seems that some S3 have another encoder) is to add 1024 bytes just before the Chroma pane.

// The encoder may need some padding before the Chroma pane
int padding = 1024;                     
if ((mWidth==640 && mHeight==480) || mWidth==1280 && mHeight==720) padding = 0;

// Interleave the U and V channel
System.arraycopy(buffer, 0, tmp, 0, mYSize); // Y
for (i = 0; i < mUVSize; i++) {
   tmp[mYSize + i*2 + padding] = buffer[mYSize + i + mUVSize]; // Cb (U)
   tmp[mYSize + i*2+1 + padding] = buffer[mYSize + i]; // Cr (V)
}
return tmp;

The camera is using YV12 and the encoder COLOR_FormatYUV420SemiPlanar.

Your snapshot shows the same kind of artefacts I had, you may need a similar hack for some resolutions, maybe with another padding length

You should also avoid resolutions that are not a multiple of 16, even on 4.3 apparently (http://code.google.com/p/android/issues/detail?id=37769) !



来源:https://stackoverflow.com/questions/17493169/getting-qualcomm-encoders-to-work-via-mediacodec-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!