[英]How to get the colorFormats supported by MediaCodec on android 4.1 and 4.2?
在android 4.1及更高版本上,我打算獲取特定MediaCodec
支持的colorFormats
列表。
Android 4.3以上提供(一個API 公共MediaCodecInfo getCodecInfo() ),以獲得MediaCodecInfo
用的特定實例相關聯的MediaCodec
。 此外,我能夠在此MediaCodecInfo
對象上調用getCapabilitiesForType ,它將獲取與我關聯的MediaCodecInfo.CodecCapabilities
對象,在該對象上我調用API colorFormats以獲取我的MediaCodec
對象的顏色格式列表。
現在,我無法在android 4.1和4.2上執行上述調用序列,僅僅是因為MediaCodec
API getCodecInfo()已添加到API級別18中。
誰能建議我如何實現相同或任何其他方法來獲取android 4.1和4.2上的顏色格式列表。
對於Android 4.1和4.2,您需要使用MediaCodecList
類來遍歷可用的編解碼器-在此您將獲得MediaCodecInfo
,它將提供與getCodecInfo()
相同的信息。
如果您使用createEncoderByType
(或createDecoderByType
)創建了編解碼器,則只有在需要getCodecInfo()
(或getName()
)的情況下,才知道您實際上在處理哪個編解碼器。 至少在AOSP中,這兩個函數僅返回MediaCodecList
中與提供的MIME類型匹配的第一個編解碼器。 (當然,有些制造商可能已對此進行了定制,但我認為這樣做的理由不多。)
因此-在4.1和4.2上-代替使用createEncoderByType
,手動遍歷MediaCodecList
的編解碼器,並選擇與您的MIME類型匹配的第一個,並在那里獲取信息和功能。
因此,簡單地說-如果您當前有以下代碼:
MediaCodec codec = MediaCodec.createEncoderByType(mimeType);
MediaCodecInfo info = codec.getCodecInfo();
然后,同樣支持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());
事實證明,有一種優雅的方法來獲取所使用的特定MediaCodec實例所支持的顏色格式,該方法可在android 4.1及更高版本上使用。 相同的解釋如下:
在執行dequeueOutputBuffer
查找錯誤代碼: MediaCodec.INFO_OUTPUT_FORMAT_CHANGED
。 在收到此錯誤代碼,調用getOutputFormat
編碼解碼器,並隨后致電getInteger
在收到MediaFormat
對象與字符串KEY_COLOR_FORMAT ,使色彩格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.