[英]How to get the colorFormats supported by MediaCodec on android 4.1 and 4.2?
On android 4.1 and above, I intend to get the list of colorFormats
supported by a particular MediaCodec
. 在android 4.1及更高版本上,我打算获取特定
MediaCodec
支持的colorFormats
列表。
Android 4.3 and above provides an API ( public MediaCodecInfo getCodecInfo () ) to get the MediaCodecInfo
associated with a particular instance of MediaCodec
. Android 4.3以上提供(一个API 公共MediaCodecInfo getCodecInfo() ),以获得
MediaCodecInfo
用的特定实例相关联的MediaCodec
。 Furthermore, I am able to call getCapabilitiesForType on this MediaCodecInfo
object which will fetch me associated MediaCodecInfo.CodecCapabilities
object, on which I call API colorFormats to get the list of color-formats for my MediaCodec
object. 此外,我能够在此
MediaCodecInfo
对象上调用getCapabilitiesForType ,它将获取与我关联的MediaCodecInfo.CodecCapabilities
对象,在该对象上我调用API colorFormats以获取我的MediaCodec
对象的颜色格式列表。
Now, I'm not able to execute above sequence of calls on android 4.1 and 4.2 simply because the MediaCodec
API getCodecInfo() is added in API level 18. 现在,我无法在android 4.1和4.2上执行上述调用序列,仅仅是因为
MediaCodec
API getCodecInfo()已添加到API级别18中。
Could anyone suggest how can I achieve the same OR any other method to get the list of color-formats on android 4.1 and 4.2. 谁能建议我如何实现相同或任何其他方法来获取android 4.1和4.2上的颜色格式列表。
For Android 4.1 and 4.2, you need to use the MediaCodecList
class to iterate through the available codecs - there you'll get the MediaCodecInfo
that will provide the same information as getCodecInfo()
does. 对于Android 4.1和4.2,您需要使用
MediaCodecList
类来遍历可用的编解码器-在此您将获得MediaCodecInfo
,它将提供与getCodecInfo()
相同的信息。
The only case where getCodecInfo()
(or getName()
) is needed if you've created the codec using createEncoderByType
(or createDecoderByType
) in which case you don't know which codec you're actually dealing with. 如果您使用
createEncoderByType
(或createDecoderByType
)创建了编解码器,则只有在需要getCodecInfo()
(或getName()
)的情况下,才知道您实际上在处理哪个编解码器。 At least in AOSP, both of these functions just return the first codec in MediaCodecList
that matches the provided MIME type. 至少在AOSP中,这两个函数仅返回
MediaCodecList
中与提供的MIME类型匹配的第一个编解码器。 (Some manufacturers might of course have customized this but I don't see much reason for it.) (当然,有些制造商可能已对此进行了定制,但我认为这样做的理由不多。)
Thus - on 4.1 and 4.2 - instead of using createEncoderByType
, manually iterate through the codecs in MediaCodecList
and pick the first one matching your MIME type, and get the info and capabilities there. 因此-在4.1和4.2上-代替使用
createEncoderByType
,手动遍历MediaCodecList
的编解码器,并选择与您的MIME类型匹配的第一个,并在那里获取信息和功能。
So, simply put - if you currently have this code: 因此,简单地说-如果您当前有以下代码:
MediaCodec codec = MediaCodec.createEncoderByType(mimeType);
MediaCodecInfo info = codec.getCodecInfo();
Then the equivalent version that supports 4.1 and 4.2 as well is: 然后,同样支持4.1和4.2的等效版本是:
MediaCodecInfo info = null;
for (int i = 0; i < MediaCodecList.getCodecCount() && info == null; i++) {
MediaCodecInfo curInfo = MediaCodecList.getCodecInfoAt(i);
if (!curInfo.isEncoder())
continue;
String[] types = curInfo.getSupportedTypes();
for (int j = 0; j < types.length; j++)
if (types[j].equals(mimeType))
info = curInfo;
}
MediaCodec codec = MediaCodec.createByCodecName(info.getName());
Turns out there is an elegant way to get the color-format supported by the particular MediaCodec instance in use, that works on android 4.1 and above. 事实证明,有一种优雅的方法来获取所使用的特定MediaCodec实例所支持的颜色格式,该方法可在android 4.1及更高版本上使用。 Same is explained below:
相同的解释如下:
While doing dequeueOutputBuffer
look out for error-code: MediaCodec.INFO_OUTPUT_FORMAT_CHANGED
. 在执行
dequeueOutputBuffer
查找错误代码: MediaCodec.INFO_OUTPUT_FORMAT_CHANGED
。 Upon receiving this error code, call getOutputFormat
on the codec and subsequently call getInteger
on the received MediaFormat
object with string KEY_COLOR_FORMAT to get the color-format. 在收到此错误代码,调用
getOutputFormat
编码解码器,并随后致电getInteger
在收到MediaFormat
对象与字符串KEY_COLOR_FORMAT ,使色彩格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.