2

I am trying to use a H264 encoder for streaming video from an Android device. For capturing the images I am using the back camera; images are in NV21 format. The codec is properly initialized, but when setting up the codec throws an error "configure failed with err 0xffffffea" with the following stack trace: http://pastebin.com/ZrpsB9cy

I have tried Google's and Qualcomm's encoders, but both throw exceptions at the same point. I am using Android SDK version 21. This is the code I have written:

private MediaCodec setupVideoCodec() {
    MediaCodec mediaCodec = null;

    try {
        mediaCodec = MediaCodec.createByCodecName("OMX.qcom.video.decoder.avc");
        MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/avc",
                VIDEO_WIDTH, VIDEO_HEIGHT);
        mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,
                MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
        mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, VIDEO_BITRATE);
        mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, STREAMING_INTERVAL);

        mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mediaCodec.start();

        Log.d(TAG, String.valueOf("Buffers available: " + mediaCodec.getInputBuffers().length));
    } catch (MediaCodec.CodecException e) {
        Log.e(TAG, e.getLocalizedMessage());
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(TAG, e.getLocalizedMessage());
        e.printStackTrace();
    }

    return mediaCodec;
}

private void encodeData(byte[] data, MediaCodec codec) {
        int inputBufferIndex = codec.dequeueInputBuffer(-1);

        if (inputBufferIndex >= 0) {
            ByteBuffer buffer = codec.getInputBuffer(inputBufferIndex);
            buffer.clear();
            buffer.put(data);
            codec.queueInputBuffer(inputBufferIndex, 0, data.length, 0, MediaCodec.BUFFER_FLAG_CODEC_CONFIG);
        }
    }

private final Camera.PreviewCallback mPreviewCbk = new Camera.PreviewCallback() {
    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {
        Log.d(TAG, "onPreviewFrame()");

        if (mVideoCodec != null) {
            mExecutor.execute(new EncodeVideo(data, mVideoCodec));
        }

        camera.addCallbackBuffer(data);
    }
};

I have checked other posts, but I have not been able to solve it. Any hint or suggestion is appreciated. Thanks in advance!

1 Answers1

0

you're trying to encode with a decoder

mediaCodec = MediaCodec.createByCodecName("OMX.qcom.video.DECODER.avc");

try

mediaCodec = MediaCodec.createByCodecName("OMX.qcom.video.encoder.avc");

instead

chris
  • 106
  • 3
  • I do not know how many times I have read the code D:.. Thank you! :) –  Apr 15 '16 at 09:56