title: How to encode Bitmaps into a video using MediaCodec?
body: <p>I would like to encode a set of Bitmaps that I have into an h264. Is this possible via MediaEncoder? I have written some code in order to do it, but the output cannot be played in any media player I have tried. Here's some of the code that I primarily borrowed from other sources that I found on Stackoverflow.</p>
  
  <pre><code>mMediaCodec = MediaCodec.createEncoderByType("video/avc");
  mMediaFormat = MediaFormat.createVideoFormat("video/avc", 320, 240);
  mMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 125000);
  mMediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
  mMediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar);
  mMediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
  mMediaCodec.configure(mMediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
  mMediaCodec.start();
  mInputBuffers = mMediaCodec.getInputBuffers();
  
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  image.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); // image is the bitmap
  byte[] input = byteArrayOutputStream.toByteArray();
  
  int inputBufferIndex = mMediaCodec.dequeueInputBuffer(-1);
  if (inputBufferIndex &gt;= 0) {
      ByteBuffer inputBuffer = mInputBuffers[inputBufferIndex];
      inputBuffer.clear();
      inputBuffer.put(input);
      mMediaCodec.queueInputBuffer(inputBufferIndex, 0, input.length, 0, 0);
  }
  </code></pre>
  
  <p>What should I adjust?</p>