我正在与MediaCodec
我正在使用它来解码.mp4
视频
MediaCodec将视频解码为YUV
格式,但我需要获取RGBA
一切正常,但我发现有几种可能的格式,例如YUV420
,YUV422
等...
据我所知,要进行转化,我需要确切知道要应用YUV420_to_RGBA
或YUV422_to_RGBA
或其他方法进行的转化...
所以,问题是-如何使用MediaCodec
来了解解码格式?
随时问。
编辑
我发现以这种方式我可以获得COLOR_FORMAT
AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);
但是,我得到了117 ...
如何知道这个数字等于多少?
答案 0 :(得分:1)
由于@fadden最终我找到了问题,我试图从不正确的AMEDIAFORMAT_KEY_COLOR_FORMAT
那里获取AMediaFormat
...
就像这样不正确
AMediaFormat *format = AMediaExtractor_getTrackFormat(ex, i);
int format_color;
AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);
这里format_color
是117
-一些无效值...
获取AMEDIAFORMAT_KEY_COLOR_FORMAT
的正确方法是
AMediaCodec *codec = AMediaCodec_createDecoderByType(mime);
AMediaCodec_configure(codec, format, nullptr, nullptr, 0);
AMediaCodec_start(codec);
int format_color;
auto format = AMediaCodec_getOutputFormat(codec);
AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);
根据此https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html format_color
21 is COLOR_FormatYUV422Flexible
= 21