如何从MediaCodec获取解码格式? [英] How to get decode format from MediaCodec?
问题描述
我正在与MediaCodec
我正在用它来解码.mp4
视频
MediaCodec将视频解码为YUV
格式,但是我需要获取RGBA
MediaCodec decode a video to YUV
format, but I need to get RGBA
一切正常,但我发现有几种可能的格式,例如YUV420
,YUV422
等...
All is ok, but I found out that there is a few possible formats like YUV420
, YUV422
and so on...
据我所知,要进行转换,我需要确切地知道要应用YUV420_to_RGBA
或YUV422_to_RGBA
或其他方法的转换...
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...
所以,问题是-如何使用MediaCodec
了解解码格式?
So, question is - how using MediaCodec
get know about decoding format?
随便问.
编辑
我发现以这种方式可以获得COLOR_FORMAT
I found out that this way I can get COLOR_FORMAT
AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);
但是,我得到了117 ...
But, I get number 117 ...
如何知道这个数字等于多少?
How to know what is this number equals?
推荐答案
由于@fadden最终我发现了问题,我试图从不正确的AMediaFormat
中获取AMEDIAFORMAT_KEY_COLOR_FORMAT
...
Thanks to @fadden eventually I found the problem, I tried to get AMEDIAFORMAT_KEY_COLOR_FORMAT
from not right AMediaFormat
...
就像这样不正确
AMediaFormat *format = AMediaExtractor_getTrackFormat(ex, i);
int format_color;
AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);
此处format_color
是117
-一些无效值...
Here format_color
was 117
- some not valid value...
获取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);
此处format_color
= 21,根据 https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html 21 is COLOR_FormatYUV422Flexible
Here format_color
= 21 according to this https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html 21 is COLOR_FormatYUV422Flexible
这篇关于如何从MediaCodec获取解码格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!