1

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

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

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 打印:

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()),但似乎没有任何效果。

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

4

1 回答 1

1

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

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

(请参阅EncodeDecodeTest。)这与 不同rewind(),尽管我有点惊讶于它不起作用——我原以为输出通常会从缓冲区的开头开始。

Android 4.3 上的VP8存在一些已知问题,尽管您似乎没有遇到这些问题。

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

于 2014-02-07T14:33:55.940 回答