title: How to compress mp4 video using MediaCodec Android?
body: <p>In my Android app, I want to compress mp4 video by changing its resolution, bitrate. I don't want to use FFmpeg (because I don't want to use NDK), so I decided to use MediaCodec API.</p>
  
  <p>Here are my logical steps:</p>
  
  <ol>
  <li>Extract video file with MediaExtractor, then decode data.</li>
  <li>Create new encoder with my new resolution, bitrate and encode data.</li>
  <li>Using MediaMuxer to create a new mp4 file.</li>
  </ol>
  
  <p>My problem is: I don't know how to setup the connection between output of decoder and input of encoder. I can decode the video to a Surface or encode a new video from a surface. But I don't understand how to connect them.</p>
  
  <p>I read these links: <a href="https://stackoverflow.com/questions/22076742/android-mediacodec-reduce-mp4-video-size">Android MediaCodec: Reduce mp4 video size</a>, <a href="https://stackoverflow.com/questions/15950610/video-compression-on-android-using-new-mediacodec-library">Video compression on android using new MediaCodec Library</a> and the example from Bigflake: <a href="https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java" rel="nofollow noreferrer">https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java</a></p>
  
  <p>Can anybody give me a clear explanation what I have to do?</p>