Tool/software:
Hi,
When I use mediacodec to encodec images, there is a error
2025-03-15 08:15:40.474 CCodecBufferChannel com.css.testvid D [c2.v4l2.avc.encoder#742] Created input block pool with allocatorID 23 => poolID 18 - OK (0)
2025-03-15 08:15:40.482 CCodecBufferChannel com.css.testvid I [c2.v4l2.avc.encoder#742] Created output block pool with allocatorID 23 => poolID 17 - OK
2025-03-15 08:15:40.483 CCodecBufferChannel com.css.testvid D [c2.v4l2.avc.encoder#742] Configured output block pool ids 17 => OK
2025-03-15 08:15:40.484 CCodecBuffers com.css.testvid D fetch graphic block failed: 14
2025-03-15 08:15:40.484 CCodecBufferChannel com.css.testvid W [c2.v4l2.avc.encoder#742] start: cannot allocate memory at all
2025-03-15 08:15:40.484 CCodec com.css.testvid E Initial preparation for Input Buffers failed
2025-03-15 08:15:40.484 MediaCodec com.css.testvid E Codec reported err 0xfffffff4/NO_MEMORY, actionCode 0, while in state 5/STARTING
My android build : am62p-userdebug 15 AP4A.250105.002.A1 eng.root test-keys
Bellow is my code, it can work on other device.
String mimeType = MediaFormat.MIMETYPE_VIDEO_AVC;
MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
MediaFormat format = MediaFormat.createVideoFormat(mimeType,1280, 720);
String encodeCodecName = codecList.findEncoderForFormat(format);
try {
MediaCodec encoder = MediaCodec.createByCodecName(encodeCodecName);
//Log.i("testEncode", "codec info:\n"+ MediaCodecInfoToString(encoder.getCodecInfo()));
int colorFormat = 0;
MediaCodecInfo.CodecCapabilities capabilities = encoder.getCodecInfo().getCapabilitiesForType(mimeType);
for (int i = 0; i < capabilities.colorFormats.length /*&& colorFormat == 0*/; i++) {
int fmt = capabilities.colorFormats[i];
switch (fmt) {
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedPlanar:
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedSemiPlanar:
case MediaCodecInfo.CodecCapabilities.COLOR_TI_FormatYUV420PackedSemiPlanar:
if (colorFormat == 0)
colorFormat = fmt;
break;
default:
break;
}
}
if(colorFormat==0)
{
Log.e("testEncode", "no supported color format");
return;
}
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
format.setInteger(MediaFormat.KEY_BIT_RATE,1024000 );
format.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
//format.setInteger(MediaFormat.KEY_BITRATE_MODE, BITRATE_MODE_VBR);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
encoder.start();
} catch (Exception e) {
e.printStackTrace();
}