如何获得媒体codeC的步幅和Y平面对齐值EN codeR [英] How to get stride and Y plane alignment values for MediaCodec encoder
问题描述
有一个关于这个问题的一些相关的问题和讨论:
There's a few related questions and discussions on this subject:
- <一个href="http://stackoverflow.com/questions/15739684/media$c$cc-and-camera-color-space-incorrect">Media$c$cc和摄像头,色彩空间不正确
- <一个href="http://stackoverflow.com/questions/17493169/getting-qualcomm-en$c$crs-to-work-via-media$c$cc-api">Getting高通EN codeRS通过媒体codeC API 工作
- https://groups.google.com/d/ MSG /安卓平台/ awaNwgb6EbY / A-YiIOwaL0QJ
- HTTPS://$c$c.google。 COM / P /安卓/问题/详细信息?ID = 37769
- Mediacodec and camera, color space incorrect
- Getting QualComm encoders to work via MediaCodec API
- https://groups.google.com/d/msg/android-platform/awaNwgb6EbY/a-YiIOwaL0QJ
- https://code.google.com/p/android/issues/detail?id=37769
我喂相机preVIEW帧( NV21
转换为 NV12
)以媒体codeC
连接codeR( NV12
又名 COLOR_FormatYUV420SemiPlanar
)。它看起来像其上运行的Android版本低于一些设备与高通
连接codeR 4.3
我有做才能收回框与正确的颜色一些输入帧的处理。
I am feeding camera preview frames (NV21
converted to NV12
) to MediaCodec
encoder (NV12
aka COLOR_FormatYUV420SemiPlanar
). It looks like that on some devices with QualComm
encoder which are running Android versions less than 4.3
I have to do some input frames processing in order to receive back frame with correct color.
在索尼Xperia ZR
运行安卓4.2.2
我要补充是
以平面排列,使其工作在几乎所有的决议。 code以上增加 1024
字节对齐的宽度不能由 32
分和 2048
字节对齐对于其它分辨率。它使媒体codeC
来恩code帧正常的,可以通过 16
可将所有的决议(除了 176×144
为其 UV
面看起来不对齐的)。
On Sony Xperia ZR
running Android 4.2.2
I have to add Y
plane alignment in order to make it working on almost all resolutions. Code above adds 1024
bytes alignment for widths which can not be divided by 32
and 2048
bytes alignment for other resolutions. It makes MediaCodec
to encode frames properly for all resolutions which can be divided by 16
(except 176x144
for which UV
plane looks misaligned).
int getYPadding() {
if (mediaCodecInfo.getName().contains("OMX.qcom") && android.os.Build.VERSION.SDK_INT < 18) {
if ((getWidth() % 32) != 0) {
return (getWidth()*getHeight()) % 1024;
} else {
return (getWidth()*getHeight()) % 2048;
}
}
return 0;
}
我试图对 LG G2
这是运行相同的安卓4.2.2
并有测试此调整高通
连接codeR,它看起来像它不工作就可以了正常。 UV
平面对齐(绿色条在画面底部)。我无法计算,这将同时适用于手机的填充。
I've tried to test this alignment on LG G2
which is running same Android 4.2.2
and has QualComm
encoder, and it looks like it does not working on it correctly. UV
plane is misaligned (a green stripe at the bottom of the frame). I was not able to calculate the padding which will work for both phones.
我也有机会获得索尼Xperia Z1
运行安卓4.3
与高通
芯片组,它看起来像它并没有这样的问题。视频上的每个分辨率看起来很好,是
面并不需要被无论如何排列。
I also have access to Sony Xperia Z1
running Android 4.3
with QualComm
chipset and it looks like it does not have such problems. Video on every resolution looks fine and Y
plane does not needs to be aligned anyhow.
据我所知,这是硬件相关的,而且可能是复杂的,但因为我要支持运行Android用户前4.3
我有一个问题。是否有可能以编程方式确定是
平面排列,垂直/水平步幅值这EN codeR期待对于给定的颜色格式?
I understand that it's hardware-related and might be complicated, but since I have to support users running Android prior to 4.3
I have a question. Is it possible to programmatically determine Y
plane alignment and vertical / horizontal stride values which encoder is expecting for the given color format?
推荐答案
在果壳中的问题:有没有 CTS测试视频编码,直到Android的4.3(API 18)。
The problem in a nutshell: there were no CTS tests for video encoding until Android 4.3 (API 18).
这样一来,对媒体codeC
在不同设备上是不一致的行为,和一些错误去忽视。该恩codeDE codeTEST 测试行使职能您再询问,并因此可以可靠地喂YUV数据到4.3+设备(虽然你仍然要运行时检测是否愿意平面或半平面)。
As a result, the behavior of MediaCodec
across different devices was inconsistent, and a few bugs went unnoticed. The EncodeDecodeTest tests exercise the functions you're asking about, and as a result you can reliably feed YUV data to a 4.3+ device (though you still have to runtime-detect whether it wants planar or semi-planar).
有关的具体问题,需要在老通设备的Y平面2K边界处,这是不太你的code正在开展的保持一致。对于720p的视频出现这种情况自然(720 * 1280 = = 450 * 2048),对于176x144的你会通过1280调整开始UV飞机在26624,而不是25344.你需要的缓冲区,而不是一个固定的范围内设定的绝对定位量填充 - 使用 uvoffset =(宽*高+ 2047)及2047
。
For your specific question, the Y plane on older Qualcomm devices needs to be aligned at a 2K boundary, which isn't quite what your code is doing. For 720p video this happens naturally (720*1280 == 450 * 2048), for 176x144 you'd adjust by 1280 to start the UV plane at 26624 instead of 25344. You need to set the absolute alignment within the buffer, not a fixed amount of padding -- use uvoffset = (width*height + 2047) & ~2047
.
您将需要检测的codeC供应商和Android的软件版本,如果它是高通pre-4.3则需要进行调整。如果您的需求发生变化,你可以针对API 18+,这些问题消失。 (你也可以使用表面
输入到媒体codeC
,避免了U / V互换的问题,虽然根据您的需要,可能未必有用。)
You will need to detect the codec vendor and Android software version, and if it's Qualcomm on pre-4.3 you need to make this adjustment. If your requirements change, and you can target API 18+, these issues go away. (And you can use Surface
input to MediaCodec
, which avoids the U/V swap issue, though depending on your needs that may not be useful.)
这篇关于如何获得媒体codeC的步幅和Y平面对齐值EN codeR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!