VP8 编码 Nexus 5 返回空/0 帧 [英] VP8 Encoding Nexus 5 returns empty/0-Frames

查看:29
本文介绍了VP8 编码 Nexus 5 返回空/0 帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的相机源编码为 VP8.问题是:当我从输出缓冲区获取帧时,字节数组的大小总是不同,但所有条目都是 0.

I'm trying to encode my camera feed to VP8. The problem is: when I get the frame from the output buffer, the byte array is always different size but all entries are 0.

这是我抓取框架并打印出来的代码:

Here's the code where I grab the frame and print it:

while (true) {
    try {
        encoderIndex = mEncoder.dequeueOutputBuffer(encoderOutputInfo, timeOut);
    } catch (Exception e) {
        e.printStackTrace();
    }
    switch (encoderIndex) {
    case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
        // something
        break;
    case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
        // something else
        break;
    case MediaCodec.INFO_TRY_AGAIN_LATER:
        // something completely different
        break;
    default:
        // get encoded frame
        byte[] frame = new byte[encoderOutputInfo.size];

        mEncoderOutputBuffers[encoderIndex].get(frame);

        Log.v(tag, "got frame. size: " + frame.length);
        Log.v(tag, "printing frame");
        Log.v(tag, printBytesAsBinary(frame));

        mEncoderOutputBuffers[encoderIndex].clear();

        // release encoder output buffer
        mEncoder.releaseOutputBuffer(encoderIndex, false);
}

还有 Logcat 打印:

And the Logcat print:

02-07 11:48:19.014: V/GoogleEncoder(24883): got frame. size: 427
02-07 11:48:19.014: V/GoogleEncoder(24883): printing frame
02-07 11:48:19.014: V/GoogleEncoder(24883): 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-07 11:48:20.544: V/GoogleEncoder(24883): got frame. size: 379
02-07 11:48:20.544: V/GoogleEncoder(24883): printing frame
02-07 11:48:20.544: V/GoogleEncoder(24883): 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

有人已经遇到过这个问题并且可以告诉我我可能做错了什么吗?我已经尝试弄乱输出缓冲区(例如 rewind()),但似乎没有任何效果.

Anyone had this problem already and can tell me what I might be doing wrong? I already tried messing with the output buffer (e.g. rewind()) but nothing seems to work.

奇怪的是,编码适用于使用 Cyanogenmod 11 的设备,它也是 4.4(在 S3 上试过)

Oddly enough, encoding works on devices with Cyanogenmod 11 which is also 4.4 (Tried on a S3)

推荐答案

MediaCodec 没有将 ByteBuffer 放在正确的位置.您需要在调用 dequeueOutputBuffer() 后手动定位它:

MediaCodec doesn't put the ByteBuffer in the correct position. You need to position it manually after the call to dequeueOutputBuffer():

int encoderStatus = encoder.dequeueOutputBuffer(info, TIMEOUT_USEC);
...
ByteBuffer encodedData = encoderOutputBuffers[encoderStatus];
encodedData.position(info.offset);
encodedData.limit(info.offset + info.size);

(参见 EncodeDecodeTest.)这与 rewind(),虽然我有点惊讶它不起作用——我原以为输出通常会在缓冲区的开头开始.

(See EncodeDecodeTest.) That's not the same as rewind(), though I'm a little surprised that didn't work -- I would have expected that output would usually start at the beginning of the buffer.

Android 4.3 上的 VP8 存在一些已知问题,虽然你似乎没有击中那些.

There are some known issues with VP8 on Android 4.3, though you don't seem to be hitting those.

如果这不能解决您的问题,了解您使用的设备(Android 和 Cyanogen 均为 S3?)、Android 软件版本以查看您用于 的代码会很有帮助configure() MediaCodec,以及使用的值.

If this does not fix your issue, it would be helpful to know the device you're using (S3 for both Android and Cyanogen?), the Android software version, to see the code you're using to configure() the MediaCodec, and what values are used.

这篇关于VP8 编码 Nexus 5 返回空/0 帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆