【问题标题】:How to get decode format from MediaCodec?如何从 MediaCodec 获取解码格式?
【发布时间】:2019-07-08 13:02:38
【问题描述】:

我正在与MediaCodec 合作

我用它来解码.mp4视频

MediaCodec 将视频解码为YUV 格式,但我需要得到RGBA

一切正常,但我发现有几种可能的格式,如YUV420YUV422 等等......

因此,据我所知,要进行转换,我需要确切知道要应用哪个转换 YUV420_to_RGBAYUV422_to_RGBA 或其他什么...

那么,问题是 - 如何使用MediaCodec 了解解码格式?

欢迎提问。

编辑

我发现这样可以得到COLOR_FORMAT

 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &format_color);

但是,我得到了 117 号 ...

如何知道这个数等于多少?

【问题讨论】:

  • 颜色格式在MediaCodecInfo.CodecCapabilities 中定义。我在列表中没有看到 117。你用的是什么设备?参见例如XBMC 获取使用视频颜色格式的示例。
  • @fadden 但在此示例中,他也使用相同的方式获取format_collor,然后与支持的格式列表进行比较。但是为什么我得到117...我签入CodecCapabilities,但没有与此数字等效的格式...
  • 可能是自定义格式,可能是错误的 MediaFormat 对象。 MediaFormat 中的其余值看起来是否有效?
  • @fadden 不,对象本身很好,所有其他值都是正确的......我想在这里问你点别的stackoverflow.com/questions/57238371/…,也许你有想法?
  • @fadden 谢谢,最终我找到了如何获得正确的价值......这只是一个愚蠢的错误......发布答案

标签: android android-mediacodec


【解决方案1】:

感谢@fadden 最终我找到了问题,我试图从不正确的AMediaFormat 得到AMEDIAFORMAT_KEY_COLOR_FORMAT...

原来是这样不对

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

这里 format_color117 - 一些无效值...

获取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

【讨论】:

    猜你喜欢
    • 2014-09-03
    • 2015-04-30
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2015-03-23
    相关资源
    最近更新 更多