Search code examples
androidarraysjpegmp4android-mediacodec

Android MediaCodec error when configure is called


I am trying to convert my JPEG frames into a MP4 video, but I have this error/warning showed on Logcat when I call the configure on the MediaCodec object:

E/Codec2Client: createComponent(c2.android.avc.encoder) -- call failed: NOT_FOUND.

The app does not crash and I am able also to call the start on MediaCodec object... I have checked all required keys for the MediaFormat from https://developer.android.com/reference/android/media/MediaFormat

I really do not understand why I have this error, thank you for any help!!!

// JPEG encoder only support this colorFormat as Input
// COLOR_FormatCbYCrY a.k.a Organized as 16bit UYVY
int colorFormat = MediaCodecInfo.CodecCapabilities.COLOR_FormatCbYCrY;

MediaFormat videoFormat = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);

// Set some properties.  Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
videoFormat.setInteger(MediaFormat.KEY_WIDTH, mWidth);
videoFormat.setInteger(MediaFormat.KEY_HEIGHT, mHeight);
videoFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
videoFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
videoFormat.setInteger(MediaFormat.KEY_FRAME_RATE, mFrameRate);
videoFormat.setInteger(MediaFormat.KEY_CAPTURE_RATE, mFrameRate);
videoFormat.setInteger(MediaFormat.KEY_DURATION, mDuration_us);
videoFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);

// Create a MediaCodec for the desired codec, then configure it as an encoder with
// our desired properties.
String codecName = codec.getName();
MediaCodec encoder = MediaCodec.createByCodecName(codecName);
encoder.configure(videoFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

Solution

  • The error was related to the unsupported color format...