Reputation: 4289
I've created an encoder using the Android's MediaCodec API using the following code :
MediaFormat mMediaFormat = MediaFormat.createVideoFormat("video/avc", width, height);
mMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate);
mMediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
mMediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
mMediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10);
Log.i(TAG, "Starting encoder");
encoder = MediaCodec.createByCodecName(Utils.selectCodec("video/avc").getName());
encoder.configure(mMediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Surface surface = encoder.createInputSurface();
encoder.start();
I'm using createInputSurface()
to pass the input to the encoder. The problem is I want RGB color-format frames in the subsequent calls to dequeueOutputBuffer()
but since I've set the color format to MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface
so I think I'm not getting RGB frames. I need to pass these frames to OpenCv for image processing.
Is there any way to get RGB frames from dequeueOutputBuffer()
?
Note : I cannot set RGB as the color format during the configuring of the encoder because it's not supported.
Upvotes: 0
Views: 2985
Reputation: 52353
The output of the encoder is AVC-encoded frames. It's not RGB or YUV, it's AVC.
The color format specifies the format of the frames you're feeding into the encoder, not what comes out, so it has no effect on what you get from dequeueOutputBuffer()
.
If you need to manipulate the raw frames, you should do so before passing them into the encoder.
Upvotes: 2