2

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 possible formats like YUV420, YUV422 and so on...

So, as far as I understand to make conversion I need to know exactly which conversion to apply YUV420_to_RGBA or YUV422_to_RGBA or something else...

So, question is - how using MediaCodec get know about decoding format?

Feel free to ask.

EDIT

I found out that this way I can get COLOR_FORMAT

 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);

But, I get number 117 ...

How to know what is this number equals?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • The color formats are defined in [MediaCodecInfo.CodecCapabilities](https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html). I don't see 117 in the list. What device are you using? See e.g. [XBMC](https://github.com/xbmc/xbmc/blob/master/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp) for an example of working with video color formats. – fadden Jul 09 '19 at 14:52
  • @fadden but in this sample he also use the same way to get `format_collor`, and then he compare with list of supported formats. But why I get `117` ... I checked in `CodecCapabilities` and there is no such format that equivalent with this number... – Sirop4ik Jul 24 '19 at 15:07
  • Could be a custom format, could be a bad MediaFormat object. Do the rest of the values in MediaFormat look valid? – fadden Jul 24 '19 at 18:31
  • @fadden no, object itself is good, all other values is correct... I would like to ask you something else here https://stackoverflow.com/questions/57238371/if-is-it-possible-to-get-bgr-from-mediacodec, maybe you have idea? – Sirop4ik Jul 28 '19 at 06:05
  • @fadden thank, eventually I found how to get the right value... It was just a stupid mistake.... Posted answer – Sirop4ik Jul 29 '19 at 13:11

1 Answers1

2

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.html 21 is COLOR_FormatYUV422Flexible

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121