【问题标题】:something about stagefright codec input format in android关于android中的stagefright编解码器输入格式的一些东西
【发布时间】:2015-02-04 08:48:46
【问题描述】:

我正在使用 stagefright videoencoder 在 android 4.4 中编码视频;

sp<AMessage> format = new AMessage;
format->setInt32("width", 1080);
format->setInt32("height", 1920);
format->setString("mime", "video/avc");
format->setInt32("color-format", OMX_COLOR_FormatYUV420Planar);
format->setInt32("bitrate", 1000000);
format->setFloat("frame-rate", 25);
format->setInt32("i-frame-interval", 5);
sp<MediaCodec> videoEncoder = MediaCodec::CreateByType(looper, "video/avc", true);
videoEncoder->configure(format, NULL, NULL,MediaCodec::CONFIGURE_FLAG_ENCODE);
videoEncoder->start();

但是当我打电话时:

status_t err = gSpVideoEncoder->dequeueOutputBuffer(&bufIndex, &offset, &size, &ptsUsec, &flags, kTimeout);

我明白了:

err === INFO_FORMAT_CHANGED

下一步,我打电话:

sp<AMessage> newFormat;
videoEncoder->getOutputFormat(&newFormat);
uint32_t width = 0, height = 0;
newFormat->findInt32("width", (int32_t *)(&width));
newFormat->findInt32("height", (int32_t *)(&height));
fprintf(stderr, "new width: %d, height: %d\n", width, height)

我得到了结果:

new width: 1088, height: 1920

我很困惑(不是 1080x1920),我是否应该向 videoEncoder 提供新的输入帧(1088x1920)?

【问题讨论】:

    标签: android stagefright


    【解决方案1】:

    视频编码要求帧尺寸与 16 的倍数对齐,即宏块尺寸。高清分辨率,即 1920 x 1080 是一种特殊情况,因为 1080 不是 16 的倍数。底层编码器希望客户端提供对齐的边界。

    在这种情况下,您可以提供如下窗口化的数据。对于Luma,您必须对齐到 16 的倍数,对于 Chroma,您必须对齐到 8 的倍数。剩余的像素可以预填充

    请注意:如果编码器能够处理 1920 x 1080 作为编码分辨率,则输出应该没问题。如果编码器使用 1920 x 1088 进行编码,由于零填充,您会在生成的比特流中观察到图片底部的绿色条带。

    ---------------------------------------------
    |                                           |
    |                                           |
    |                                           |
    |                   Luma                    |
    |                1920 x 1080                |
    |                filled into                |
    |                a buffer of                |
    |                1920 x 1088                |
    |                                           |
    |                Last 8 lines could         |
    |                be filled with zeroes      |
    |                                           |
    ---------------------------------------------
    -----------------------
    |        Cb           |
    |   960 x 540         |
    |   filled into       |
    |   a buffer of       |
    |   960 x 544         |
    |                     |
    -----------------------
    -----------------------
    |        Cr           |
    |   960 x 540         |
    |   filled into       |
    |   a buffer of       |
    |   960 x 544         |
    |                     |
    -----------------------
    

    【讨论】:

    • @BingShine.. 如果解决方案解决了您的问题,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 2014-11-06
    相关资源
    最近更新 更多