Skip to content Skip to sidebar Skip to footer

How To Get Decode Format From Mediacodec?

I am working with MediaCodec I am using it for decode .mp4 video MediaCodec decode a video to YUV format, but I need to get RGBA All is ok, but I found out that there is a few po

Solution 1:

Thanks to @fadden eventually I found the problem, I tried to get AMEDIAFORMAT_KEY_COLOR_FORMAT from not right AMediaFormat...

It was like this NOT RIGHT

AMediaFormat *format = AMediaExtractor_getTrackFormat(ex, i);
int format_color;
AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);

Here format_color was 117 - some not valid value...

Right way to get AMEDIAFORMAT_KEY_COLOR_FORMAT is

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);

Here format_color = 21 according to this https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html21 is COLOR_FormatYUV422Flexible

Post a Comment for "How To Get Decode Format From Mediacodec?"