问题
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?
回答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.html 21 is COLOR_FormatYUV422Flexible
来源:https://stackoverflow.com/questions/56935547/how-to-get-decode-format-from-mediacodec